Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(extensions): enable WebSQL in background pages #25071

Merged
merged 4 commits into from Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions shell/browser/electron_browser_client.cc
Expand Up @@ -770,6 +770,16 @@ void ElectronBrowserClient::AppendExtraCommandLineSwitches(
command_line->AppendSwitch("profile-electron-init");
}

// Extension background pages don't have WebContentsPreferences, but they
// support WebSQL by default.
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
content::RenderProcessHost* process =
content::RenderProcessHost::FromID(process_id);
if (extensions::ProcessMap::Get(process->GetBrowserContext())
->Contains(process_id))
command_line->AppendSwitch(switches::kEnableWebSQL);
#endif

content::WebContents* web_contents =
GetWebContentsFromProcessID(process_id);
if (web_contents) {
Expand Down
14 changes: 13 additions & 1 deletion spec-main/extensions-spec.ts
Expand Up @@ -37,6 +37,18 @@ describe('chrome extensions', () => {
});
});

it('can open WebSQLDatabase in a background page', async () => {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`);
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession, sandbox: true } });
w.loadURL('about:blank');

await emittedOnce(w.webContents, 'dom-ready');
await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
const args: any = await emittedOnce(app, 'web-contents-created');
const wc: Electron.WebContents = args[1];
await expect(wc.executeJavaScript('(()=>{try{openDatabase("t", "1.0", "test", 2e5);return true;}catch(e){throw e}})()')).to.not.be.rejected();
});

function fetch (contents: WebContents, url: string) {
return contents.executeJavaScript(`fetch(${JSON.stringify(url)})`);
}
Expand Down Expand Up @@ -292,7 +304,7 @@ describe('chrome extensions', () => {
await customSession.loadExtension(path.join(fixtures, 'extensions', 'persistent-background-page'));
const w = new BrowserWindow({ show: false, webPreferences: { session: customSession } });
const promise = emittedOnce(app, 'web-contents-created');
await w.loadURL(`about:blank`);
await w.loadURL('about:blank');
const [, bgPageContents] = await promise;
expect(bgPageContents.session).to.not.equal(undefined);
});
Expand Down