fix: assign session to remote webContents (#23989)

* fix: assign session to remote webContents

* fix: test name
This commit is contained in:
Eryk Rakowski 2020-06-11 05:57:51 +02:00 committed by GitHub
parent a33c10c3ed
commit 04be1ac4a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 1 deletions

View file

@ -393,6 +393,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

@ -1,5 +1,5 @@
import { expect } from 'chai';
import { session, BrowserWindow, ipcMain, WebContents, Extension } from 'electron/main';
import { app, session, BrowserWindow, ipcMain, WebContents, Extension } from 'electron/main';
import { closeAllWindows, closeWindow } from './window-helpers';
import * as http from 'http';
import { AddressInfo } from 'net';
@ -269,6 +269,16 @@ describe('chrome extensions', () => {
});
});
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
}