browser(firefox): fix addBinding on pages with CSP (#6470)

This commit is contained in:
Dmitry Gozman 2021-05-08 18:06:56 -07:00 committed by GitHub
parent 2d4538c23d
commit f1a65820f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 36 deletions

View File

@ -1,2 +1,2 @@
1246
Changed: pavel.feldman@gmail.com Fri 07 May 2021 09:10:22 PM PDT
1247
Changed: dgozman@gmail.com Sat May 8 17:46:11 PDT 2021

View File

@ -471,7 +471,18 @@ class Frame {
}, this.domWindow(), {
defineAs: name,
});
this.domWindow().eval(script);
if (this._executionContext)
this._evaluateScriptSafely(this._executionContext, script);
}
_evaluateScriptSafely(executionContext, script) {
try {
let result = executionContext.evaluateScript(script);
if (result && result.objectId)
executionContext.disposeObject(result.objectId);
} catch (e) {
dump(`ERROR: ${e.message}\n${e.stack}\n`);
}
}
_onGlobalObjectCleared() {
@ -489,27 +500,15 @@ class Frame {
});
for (const [name, script] of this._frameTree._bindings)
this._addBinding(name, script);
for (const script of this._frameTree._scriptsToEvaluateOnNewDocument.values()) {
try {
const result = this._executionContext.evaluateScript(script);
if (result && result.objectId)
this._executionContext.disposeObject(result.objectId);
} catch (e) {
dump(`ERROR: ${e.message}\n${e.stack}\n`);
}
}
for (const script of this._frameTree._scriptsToEvaluateOnNewDocument.values())
this._evaluateScriptSafely(this._executionContext, script);
for (const world of this._isolatedWorlds.values())
this._runtime.destroyExecutionContext(world);
this._isolatedWorlds.clear();
for (const {script, worldName} of this._frameTree._isolatedWorlds.values()) {
const context = worldName ? this.createIsolatedWorld(worldName) : this.executionContext();
try {
let result = context.evaluateScript(script);
if (result && result.objectId)
context.disposeObject(result.objectId);
} catch (e) {
}
this._evaluateScriptSafely(context, script);
}
}

View File

@ -1,2 +1,2 @@
1256
Changed: pavel.feldman@gmail.com Fri 07 May 2021 09:00:05 PM PDT
1257
Changed: dgozman@gmail.com Sat May 8 17:46:11 PDT 2021

View File

@ -471,7 +471,18 @@ class Frame {
}, this.domWindow(), {
defineAs: name,
});
this.domWindow().eval(script);
if (this._executionContext)
this._evaluateScriptSafely(this._executionContext, script);
}
_evaluateScriptSafely(executionContext, script) {
try {
let result = executionContext.evaluateScript(script);
if (result && result.objectId)
executionContext.disposeObject(result.objectId);
} catch (e) {
dump(`ERROR: ${e.message}\n${e.stack}\n`);
}
}
_onGlobalObjectCleared() {
@ -489,27 +500,15 @@ class Frame {
});
for (const [name, script] of this._frameTree._bindings)
this._addBinding(name, script);
for (const script of this._frameTree._scriptsToEvaluateOnNewDocument.values()) {
try {
const result = this._executionContext.evaluateScript(script);
if (result && result.objectId)
this._executionContext.disposeObject(result.objectId);
} catch (e) {
dump(`ERROR: ${e.message}\n${e.stack}\n`);
}
}
for (const script of this._frameTree._scriptsToEvaluateOnNewDocument.values())
this._evaluateScriptSafely(this._executionContext, script);
for (const world of this._isolatedWorlds.values())
this._runtime.destroyExecutionContext(world);
this._isolatedWorlds.clear();
for (const {script, worldName} of this._frameTree._isolatedWorlds.values()) {
const context = worldName ? this.createIsolatedWorld(worldName) : this.executionContext();
try {
let result = context.evaluateScript(script);
if (result && result.objectId)
context.disposeObject(result.objectId);
} catch (e) {
}
this._evaluateScriptSafely(context, script);
}
}