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 1247
Changed: pavel.feldman@gmail.com Fri 07 May 2021 09:10:22 PM PDT Changed: dgozman@gmail.com Sat May 8 17:46:11 PDT 2021

View file

@ -471,7 +471,18 @@ class Frame {
}, this.domWindow(), { }, this.domWindow(), {
defineAs: name, 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() { _onGlobalObjectCleared() {
@ -489,27 +500,15 @@ class Frame {
}); });
for (const [name, script] of this._frameTree._bindings) for (const [name, script] of this._frameTree._bindings)
this._addBinding(name, script); this._addBinding(name, script);
for (const script of this._frameTree._scriptsToEvaluateOnNewDocument.values()) { for (const script of this._frameTree._scriptsToEvaluateOnNewDocument.values())
try { this._evaluateScriptSafely(this._executionContext, script);
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 world of this._isolatedWorlds.values()) for (const world of this._isolatedWorlds.values())
this._runtime.destroyExecutionContext(world); this._runtime.destroyExecutionContext(world);
this._isolatedWorlds.clear(); this._isolatedWorlds.clear();
for (const {script, worldName} of this._frameTree._isolatedWorlds.values()) { for (const {script, worldName} of this._frameTree._isolatedWorlds.values()) {
const context = worldName ? this.createIsolatedWorld(worldName) : this.executionContext(); const context = worldName ? this.createIsolatedWorld(worldName) : this.executionContext();
try { this._evaluateScriptSafely(context, script);
let result = context.evaluateScript(script);
if (result && result.objectId)
context.disposeObject(result.objectId);
} catch (e) {
}
} }
} }

View file

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

View file

@ -471,7 +471,18 @@ class Frame {
}, this.domWindow(), { }, this.domWindow(), {
defineAs: name, 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() { _onGlobalObjectCleared() {
@ -489,27 +500,15 @@ class Frame {
}); });
for (const [name, script] of this._frameTree._bindings) for (const [name, script] of this._frameTree._bindings)
this._addBinding(name, script); this._addBinding(name, script);
for (const script of this._frameTree._scriptsToEvaluateOnNewDocument.values()) { for (const script of this._frameTree._scriptsToEvaluateOnNewDocument.values())
try { this._evaluateScriptSafely(this._executionContext, script);
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 world of this._isolatedWorlds.values()) for (const world of this._isolatedWorlds.values())
this._runtime.destroyExecutionContext(world); this._runtime.destroyExecutionContext(world);
this._isolatedWorlds.clear(); this._isolatedWorlds.clear();
for (const {script, worldName} of this._frameTree._isolatedWorlds.values()) { for (const {script, worldName} of this._frameTree._isolatedWorlds.values()) {
const context = worldName ? this.createIsolatedWorld(worldName) : this.executionContext(); const context = worldName ? this.createIsolatedWorld(worldName) : this.executionContext();
try { this._evaluateScriptSafely(context, script);
let result = context.evaluateScript(script);
if (result && result.objectId)
context.disposeObject(result.objectId);
} catch (e) {
}
} }
} }