fix(page): support multiple bootstrap scripts (#59)
This commit is contained in:
parent
7c69f8c457
commit
ef847b1941
|
|
@ -48,6 +48,7 @@ export class Page extends EventEmitter {
|
|||
private _mouse: Mouse;
|
||||
private _timeoutSettings: TimeoutSettings;
|
||||
private _frameManager: FrameManager;
|
||||
private _bootstrapScripts: string[] = [];
|
||||
_javascriptEnabled = true;
|
||||
private _viewport: Viewport | null = null;
|
||||
private _screenshotTaskQueue: TaskQueue;
|
||||
|
|
@ -346,7 +347,10 @@ export class Page extends EventEmitter {
|
|||
}
|
||||
|
||||
async evaluateOnNewDocument(pageFunction: Function | string, ...args: Array<any>) {
|
||||
const source = helper.evaluationString(pageFunction, ...args);
|
||||
const script = helper.evaluationString(pageFunction, ...args);
|
||||
this._bootstrapScripts.push(script);
|
||||
const source = this._bootstrapScripts.join(';');
|
||||
// TODO(yurys): support process swap on navigation.
|
||||
await this._session.send('Page.setBootstrapScript', { source });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -264,6 +264,17 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
|
|||
await page.goto(server.PREFIX + '/tamperable.html');
|
||||
expect(await page.evaluate(() => window.result)).toBe(123);
|
||||
});
|
||||
fit('should support multiple scripts', async({page, server}) => {
|
||||
await page.evaluateOnNewDocument(function(){
|
||||
window.script1 = 1;
|
||||
});
|
||||
await page.evaluateOnNewDocument(function(){
|
||||
window.script2 = 2;
|
||||
});
|
||||
await page.goto(server.PREFIX + '/tamperable.html');
|
||||
expect(await page.evaluate(() => window.script1)).toBe(1);
|
||||
expect(await page.evaluate(() => window.script2)).toBe(2);
|
||||
});
|
||||
it('should work with CSP', async({page, server}) => {
|
||||
server.setCSP('/empty.html', 'script-src ' + server.PREFIX);
|
||||
await page.evaluateOnNewDocument(function(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue