fix(addInitScript): tolerate trailing comments (#13275)
This commit is contained in:
parent
66a95c6897
commit
b0103566c9
|
|
@ -43,7 +43,7 @@ export async function evaluationScript(fun: Function | string | { path?: string,
|
|||
if (fun.path !== undefined) {
|
||||
let source = await fs.promises.readFile(fun.path, 'utf8');
|
||||
if (addSourceUrl)
|
||||
source += '//# sourceURL=' + fun.path.replace(/\n/g, '');
|
||||
source += '\n//# sourceURL=' + fun.path.replace(/\n/g, '');
|
||||
return source;
|
||||
}
|
||||
throw new Error('Either path or content property must be present');
|
||||
|
|
|
|||
|
|
@ -777,7 +777,7 @@ export class WKPage implements PageDelegate {
|
|||
scripts.push(this._bindingToScript(binding));
|
||||
scripts.push(...this._browserContext.initScripts);
|
||||
scripts.push(...this._page.initScripts);
|
||||
return scripts.join(';');
|
||||
return scripts.join(';\n');
|
||||
}
|
||||
|
||||
async _updateBootstrapScript(): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,13 @@ it('should throw without path and content', async ({ page }) => {
|
|||
expect(error.message).toContain('Either path or content property must be present');
|
||||
});
|
||||
|
||||
it('should work with trailing comments', async ({ page, asset }) => {
|
||||
await page.addInitScript({ content: '// comment' });
|
||||
await page.addInitScript({ content: 'window.secret = 42;' });
|
||||
await page.goto('data:text/html,<html></html>');
|
||||
expect(await page.evaluate('secret')).toBe(42);
|
||||
});
|
||||
|
||||
it('should support multiple scripts', async ({ page, server }) => {
|
||||
await page.addInitScript(function() {
|
||||
window['script1'] = 1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue