fix(webkit): define window.GestureEvent (#22768)

Polyfill GestureEvent so that Safari detection works.

Fixes #22735
This commit is contained in:
Yury Semikhatsky 2023-05-05 11:37:28 -07:00 committed by GitHub
parent 160888df99
commit 02a1a2e6a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -788,6 +788,7 @@ export class WKPage implements PageDelegate {
scripts.push('delete window.ondeviceorientation');
}
scripts.push('if (!window.safari) window.safari = {};');
scripts.push('if (!window.GestureEvent) window.GestureEvent = function GestureEvent() {};');
for (const binding of this._page.allBindings())
scripts.push(binding.source);

View File

@ -241,3 +241,12 @@ it('loading in HTMLImageElement.prototype', async ({ page, server, browserName }
const defined = await page.evaluate(() => 'loading' in HTMLImageElement.prototype);
expect(defined).toBeTruthy();
});
it('window.GestureEvent in WebKit', async ({ page, server, browserName }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/22735' });
await page.goto(server.EMPTY_PAGE);
const defined = await page.evaluate(() => 'GestureEvent' in window);
expect(defined).toBe(browserName === 'webkit');
const type = await page.evaluate(() => typeof (window as any).GestureEvent);
expect(type).toBe(browserName === 'webkit' ? 'function' : 'undefined');
});