feat(page): add Page.setJavaScriptEnabled for WebKit (#125)

This commit is contained in:
Yury Semikhatsky 2019-12-03 11:47:02 -07:00 committed by Dmitry Gozman
parent 6b3c2632e7
commit ba54ad46b3
3 changed files with 15 additions and 4 deletions

View File

@ -471,8 +471,9 @@ export class Frame {
// In case of multiple sessions to the same target, there's a race between
// connections so we might end up creating multiple isolated worlds.
// We can use either.
if (!world.context)
this._setContext(worldType, context);
if (world.context)
this._setContext(worldType, null);
this._setContext(worldType, context);
}
_contextDestroyed(context: js.ExecutionContext) {

View File

@ -348,6 +348,13 @@ export class Page extends EventEmitter {
await this._session.send('Page.setBootstrapScript', { source });
}
async setJavaScriptEnabled(enabled: boolean) {
if (this._javascriptEnabled === enabled)
return;
this._javascriptEnabled = enabled;
await this._session.send('Emulation.setJavaScriptEnabled', { enabled });
}
async setCacheEnabled(enabled: boolean = true) {
await this._frameManager.networkManager().setCacheEnabled(enabled);
}

View File

@ -831,12 +831,15 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
});
describe('Page.setJavaScriptEnabled', function() {
it.skip(WEBKIT)('should work', async({page, server}) => {
it('should work', async({page, server}) => {
await page.setJavaScriptEnabled(false);
await page.goto('data:text/html, <script>var something = "forbidden"</script>');
let error = null;
await page.evaluate('something').catch(e => error = e);
expect(error.message).toContain('something is not defined');
if (WEBKIT)
expect(error.message).toContain('Can\'t find variable: something');
else
expect(error.message).toContain('something is not defined');
await page.setJavaScriptEnabled(true);
await page.goto('data:text/html, <script>var something = "forbidden"</script>');