mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-07 03:39:48 +03:00
fix(chromium): install binding function during initialization (#1320)
This commit is contained in:
parent
65d10a5d5d
commit
3dd49459bb
@ -92,11 +92,16 @@ export class CRPage implements PageDelegate {
|
|||||||
helper.addEventListener(this._client, 'Target.attachedToTarget', event => this._onAttachedToTarget(event)),
|
helper.addEventListener(this._client, 'Target.attachedToTarget', event => this._onAttachedToTarget(event)),
|
||||||
helper.addEventListener(this._client, 'Target.detachedFromTarget', event => this._onDetachedFromTarget(event)),
|
helper.addEventListener(this._client, 'Target.detachedFromTarget', event => this._onDetachedFromTarget(event)),
|
||||||
];
|
];
|
||||||
this._page.frames().map(frame => this._client.send('Page.createIsolatedWorld', {
|
for (const frame of this._page.frames()) {
|
||||||
frameId: frame._id,
|
// Note: frames might be removed before we send these.
|
||||||
grantUniveralAccess: true,
|
this._client.send('Page.createIsolatedWorld', {
|
||||||
worldName: UTILITY_WORLD_NAME,
|
frameId: frame._id,
|
||||||
}).catch(debugError)); // frames might be removed before we send this.
|
grantUniveralAccess: true,
|
||||||
|
worldName: UTILITY_WORLD_NAME,
|
||||||
|
}).catch(debugError);
|
||||||
|
for (const binding of this._browserContext._pageBindings.values())
|
||||||
|
frame.evaluate(binding.source).catch(debugError);
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
this._client.send('Log.enable', {}),
|
this._client.send('Log.enable', {}),
|
||||||
this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }),
|
this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }),
|
||||||
|
@ -612,6 +612,8 @@ export class PageBinding {
|
|||||||
|
|
||||||
function addPageBinding(bindingName: string) {
|
function addPageBinding(bindingName: string) {
|
||||||
const binding = (window as any)[bindingName];
|
const binding = (window as any)[bindingName];
|
||||||
|
if (binding.__installed)
|
||||||
|
return;
|
||||||
(window as any)[bindingName] = (...args: any[]) => {
|
(window as any)[bindingName] = (...args: any[]) => {
|
||||||
const me = (window as any)[bindingName];
|
const me = (window as any)[bindingName];
|
||||||
let callbacks = me['callbacks'];
|
let callbacks = me['callbacks'];
|
||||||
@ -625,4 +627,5 @@ function addPageBinding(bindingName: string) {
|
|||||||
binding(JSON.stringify({name: bindingName, seq, args}));
|
binding(JSON.stringify({name: bindingName, seq, args}));
|
||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
(window as any)[bindingName].__installed = true;
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('BrowserContext.exposeFunction', () => {
|
describe('BrowserContext.exposeFunction', () => {
|
||||||
it.fail(CHROMIUM || FFOX)('should work', async({browser, server}) => {
|
it.fail(FFOX)('should work', async({browser, server}) => {
|
||||||
const context = await browser.newContext();
|
const context = await browser.newContext();
|
||||||
await context.exposeFunction('add', (a, b) => a + b);
|
await context.exposeFunction('add', (a, b) => a + b);
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
Loading…
Reference in New Issue
Block a user