fix: assign session to remote webContents (#24065)

Co-authored-by: Eryk Rakowski <sentialx@gmail.com>
This commit is contained in:
Cheng Zhao
2020-06-11 23:07:20 +09:00
committed by GitHub
parent 974be18991
commit 9a7c2fa2af
4 changed files with 23 additions and 0 deletions

View File

@@ -385,6 +385,9 @@ WebContents::WebContents(v8::Isolate* isolate,
: content::WebContentsObserver(web_contents),
type_(Type::REMOTE),
weak_factory_(this) {
auto session = Session::CreateFrom(isolate, GetBrowserContext());
session_.Reset(isolate, session.ToV8());
web_contents->SetUserAgentOverride(blink::UserAgentOverride::UserAgentOnly(
GetBrowserContext()->GetUserAgent()),
false);

View File

@@ -264,6 +264,16 @@ ifdescribe(process.electronBinding('features').isExtensionsEnabled())('chrome ex
});
});
it('has session in background page', async () => {
const customSession = session.fromPartition(`persist:${require('uuid').v4()}`);
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`);
const [, bgPageContents] = await promise;
expect(bgPageContents.session).to.not.equal(undefined);
});
describe('devtools extensions', () => {
let showPanelTimeoutId: any = null;
afterEach(() => {

View File

@@ -0,0 +1 @@
/* eslint-disable no-undef */

View File

@@ -0,0 +1,9 @@
{
"name": "persistent-background-page",
"version": "1.0",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"manifest_version": 2
}