Skip to content

Commit

Permalink
feat(page): add Page.setJavaScriptEnabled for WebKit (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored and dgozman committed Dec 3, 2019
1 parent 6b3c263 commit ba54ad4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/webkit/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions test/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>');
Expand Down

0 comments on commit ba54ad4

Please sign in to comment.