fix: assign session to remote webContents (#23989)
* fix: assign session to remote webContents * fix: test name
This commit is contained in:
parent
a33c10c3ed
commit
04be1ac4a1
4 changed files with 24 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/* eslint-disable no-undef */
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "persistent-background-page",
|
||||
"version": "1.0",
|
||||
"background": {
|
||||
"scripts": ["background.js"],
|
||||
"persistent": true
|
||||
},
|
||||
"manifest_version": 2
|
||||
}
|
Loading…
Reference in a new issue