fix: expose window.safari in webkit (#21361)

The actual API of the object is not implemented because those who want
to test it will likely need their own mock and for the browser detection
logic (as described in the bug) just having the property on window
should be sufficient.

Fixes #21037
This commit is contained in:
Yury Semikhatsky 2023-03-03 13:38:13 -08:00 committed by GitHub
parent 26fa0eeae8
commit be259dac7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -785,6 +785,8 @@ export class WKPage implements PageDelegate {
scripts.push('delete window.ondevicemotion');
scripts.push('delete window.ondeviceorientation');
}
scripts.push('if (!window.safari) window.safari = {};');
for (const binding of this._page.allBindings())
scripts.push(binding.source);
scripts.push(...this._browserContext.initScripts);

View File

@ -200,3 +200,11 @@ it('serviceWorker should intercept document request', async ({ page, server, bro
await page.reload();
expect(await page.textContent('body')).toBe('intercepted');
});
it('webkit should define window.safari', async ({ page, server, browserName }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21037' });
it.skip(browserName !== 'webkit');
await page.goto(server.EMPTY_PAGE);
const defined = await page.evaluate(() => !!(window as any).safari);
expect(defined).toBeTruthy();
});