fix(wk): make evaluateOnNewDocument work with PSON (#326)
This commit is contained in:
parent
49fc5a8e52
commit
701b5db452
|
|
@ -68,6 +68,10 @@ export class WKFrameManager implements PageDelegate {
|
||||||
this._addSessionListeners();
|
this._addSessionListeners();
|
||||||
this._networkManager.setSession(session);
|
this._networkManager.setSession(session);
|
||||||
this._isolatedWorlds = new Set();
|
this._isolatedWorlds = new Set();
|
||||||
|
// New bootstrap scripts may have been added during provisional load, push them
|
||||||
|
// again to be on the safe side.
|
||||||
|
if (this._setBootstrapScripts.length)
|
||||||
|
this._setBootstrapScripts(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method is called for provisional targets as well. The session passed as the parameter
|
// This method is called for provisional targets as well. The session passed as the parameter
|
||||||
|
|
@ -95,6 +99,8 @@ export class WKFrameManager implements PageDelegate {
|
||||||
promises.push(this._setEmulateMedia(session, this._page._state.mediaType, this._page._state.colorScheme));
|
promises.push(this._setEmulateMedia(session, this._page._state.mediaType, this._page._state.colorScheme));
|
||||||
if (contextOptions.javaScriptEnabled === false)
|
if (contextOptions.javaScriptEnabled === false)
|
||||||
promises.push(session.send('Emulation.setJavaScriptEnabled', { enabled: false }));
|
promises.push(session.send('Emulation.setJavaScriptEnabled', { enabled: false }));
|
||||||
|
if (this._setBootstrapScripts.length && session.isProvisional())
|
||||||
|
this._setBootstrapScripts(session);
|
||||||
if (contextOptions.bypassCSP)
|
if (contextOptions.bypassCSP)
|
||||||
promises.push(session.send('Page.setBypassCSP', { enabled: true }));
|
promises.push(session.send('Page.setBypassCSP', { enabled: true }));
|
||||||
if (this._page._state.extraHTTPHeaders !== null)
|
if (this._page._state.extraHTTPHeaders !== null)
|
||||||
|
|
@ -322,16 +328,18 @@ export class WKFrameManager implements PageDelegate {
|
||||||
async exposeBinding(name: string, bindingFunction: string): Promise<void> {
|
async exposeBinding(name: string, bindingFunction: string): Promise<void> {
|
||||||
const script = `self.${name} = (param) => console.debug('${BINDING_CALL_MESSAGE}', {}, param); ${bindingFunction}`;
|
const script = `self.${name} = (param) => console.debug('${BINDING_CALL_MESSAGE}', {}, param); ${bindingFunction}`;
|
||||||
this._bootstrapScripts.unshift(script);
|
this._bootstrapScripts.unshift(script);
|
||||||
const source = this._bootstrapScripts.join(';');
|
await this._setBootstrapScripts(this._session);
|
||||||
await this._session.send('Page.setBootstrapScript', { source });
|
|
||||||
await Promise.all(this._page.frames().map(frame => frame.evaluate(script).catch(debugError)));
|
await Promise.all(this._page.frames().map(frame => frame.evaluate(script).catch(debugError)));
|
||||||
}
|
}
|
||||||
|
|
||||||
async evaluateOnNewDocument(script: string): Promise<void> {
|
async evaluateOnNewDocument(script: string): Promise<void> {
|
||||||
this._bootstrapScripts.push(script);
|
this._bootstrapScripts.push(script);
|
||||||
|
await this._setBootstrapScripts(this._session);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _setBootstrapScripts(session: WKTargetSession) {
|
||||||
const source = this._bootstrapScripts.join(';');
|
const source = this._bootstrapScripts.join(';');
|
||||||
// TODO(yurys): support process swap on navigation.
|
await session.send('Page.setBootstrapScript', { source });
|
||||||
await this._session.send('Page.setBootstrapScript', { source });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async closePage(runBeforeUnload: boolean): Promise<void> {
|
async closePage(runBeforeUnload: boolean): Promise<void> {
|
||||||
|
|
|
||||||
|
|
@ -297,7 +297,7 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
|
||||||
await page.addScriptTag({content: 'window.e = 10;'}).catch(e => void e);
|
await page.addScriptTag({content: 'window.e = 10;'}).catch(e => void e);
|
||||||
expect(await page.evaluate(() => window.e)).toBe(undefined);
|
expect(await page.evaluate(() => window.e)).toBe(undefined);
|
||||||
});
|
});
|
||||||
it.skip(WEBKIT)('should work after a cross origin navigation', async({page, server}) => {
|
it('should work after a cross origin navigation', async({page, server}) => {
|
||||||
await page.goto(server.CROSS_PROCESS_PREFIX);
|
await page.goto(server.CROSS_PROCESS_PREFIX);
|
||||||
await page.evaluateOnNewDocument(function(){
|
await page.evaluateOnNewDocument(function(){
|
||||||
window.injected = 123;
|
window.injected = 123;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue