Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
browser(firefox): fix addBinding on pages with CSP (#6470)
Dmitry Gozmanf1a65820f40e
diff --git a/browser_patches/firefox-stable/BUILD_NUMBER b/browser_patches/firefox-stable/BUILD_NUMBERindex e38e7ba6dc..b8e1107465 100644--- a/browser_patches/firefox-stable/BUILD_NUMBER+++ b/browser_patches/firefox-stable/BUILD_NUMBER@@ -1,2 +1,2 @@-1246-Changed: [email protected] Fri 07 May 2021 09:10:22 PM PDT+1247+Changed: [email protected] Sat May 8 17:46:11 PDT 2021diff --git a/browser_patches/firefox-stable/juggler/content/FrameTree.js b/browser_patches/firefox-stable/juggler/content/FrameTree.jsindex 4380dc7f8e..8a55330a5d 100644--- a/browser_patches/firefox-stable/juggler/content/FrameTree.js+++ b/browser_patches/firefox-stable/juggler/content/FrameTree.js@@ -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);}}diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBERindex 5849ce373e..9f8a635f23 100644--- a/browser_patches/firefox/BUILD_NUMBER+++ b/browser_patches/firefox/BUILD_NUMBER@@ -1,2 +1,2 @@-1256-Changed: [email protected] Fri 07 May 2021 09:00:05 PM PDT+1257+Changed: [email protected] Sat May 8 17:46:11 PDT 2021diff --git a/browser_patches/firefox/juggler/content/FrameTree.js b/browser_patches/firefox/juggler/content/FrameTree.jsindex 4380dc7f8e..8a55330a5d 100644--- a/browser_patches/firefox/juggler/content/FrameTree.js+++ b/browser_patches/firefox/juggler/content/FrameTree.js@@ -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);}}