Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(webkit): rewrite global object retrieval errors (#640)

Dmitry Gozmanf1d1dfb08170
diff --git a/src/webkit/wkExecutionContext.ts b/src/webkit/wkExecutionContext.ts
index 0af625adbd..69f3f53be0 100644
--- a/src/webkit/wkExecutionContext.ts
+++ b/src/webkit/wkExecutionContext.ts
@@ -111,7 +111,15 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {
serializableArgs = args;
}
- const thisObjectId = await this._contextGlobalObjectId();
+ let thisObjectId;
+ try {
+ thisObjectId = await this._contextGlobalObjectId();
+ } catch (error) {
+ if (error.message.includes('Missing injected script for given'))
+ throw new Error('Execution context was destroyed, most likely because of a navigation.');
+ throw error;
+ }
+
let callFunctionOnPromise;
try {
callFunctionOnPromise = this._session.send('Runtime.callFunctionOn', {
diff --git a/test/screenshot.spec.js b/test/screenshot.spec.js
index 3d08f687fe..f4c9ae4237 100644
--- a/test/screenshot.spec.js
+++ b/test/screenshot.spec.js
@@ -181,8 +181,8 @@ module.exports.describe = function({testRunner, expect, product, FFOX, CHROMIUM,
const screenshot = await page.screenshot();
expect(screenshot).toBeGolden('screenshot-webgl.png');
});
- // firefox and webkit are flaky
- it.skip(FFOX || WEBKIT)('should work while navigating', async({page, server}) => {
+ // firefox is flaky
+ it.skip(FFOX)('should work while navigating', async({page, server}) => {
await page.setViewport({width: 500, height: 500});
await page.goto(server.PREFIX + '/redirectloop1.html');
for (let i = 0; i < 10; i++) {