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: make preload calculation identical between sandbox & non-sandboxed #34531

Merged
merged 7 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 4 additions & 8 deletions lib/renderer/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as path from 'path';
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';

import type * as ipcRendererInternalModule from '@electron/internal/renderer/ipc-renderer-internal';
import type * as ipcRendererUtilsModule from '@electron/internal/renderer/ipc-renderer-internal-utils';

const Module = require('module');

Expand Down Expand Up @@ -38,6 +39,7 @@ require('../common/reset-search-paths');
require('@electron/internal/common/init');

const { ipcRendererInternal } = require('@electron/internal/renderer/ipc-renderer-internal') as typeof ipcRendererInternalModule;
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils') as typeof ipcRendererUtilsModule;

process.getProcessMemoryInfo = () => {
return ipcRendererInternal.invoke<Electron.ProcessMemoryInfo>(IPC_MESSAGES.BROWSER_GET_PROCESS_MEMORY_INFO);
Expand All @@ -48,15 +50,8 @@ const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_co
const { mainFrame } = process._linkedBinding('electron_renderer_web_frame');

const nodeIntegration = mainFrame.getWebPreference('nodeIntegration');
const preloadScript = mainFrame.getWebPreference('preload');
nornagon marked this conversation as resolved.
Show resolved Hide resolved
const preloadScripts = mainFrame.getWebPreference('preloadScripts');
const appPath = hasSwitch('app-path') ? getSwitchValue('app-path') : null;

// The webContents preload script is loaded after the session preload scripts.
if (preloadScript) {
preloadScripts.push(preloadScript);
}

// Common renderer initialization
require('@electron/internal/renderer/common-init');

Expand Down Expand Up @@ -127,8 +122,9 @@ if (nodeIntegration) {
}
}

const { preloadScripts } = ipcRendererUtils.invokeSync(IPC_MESSAGES.BROWSER_SANDBOX_LOAD);
nornagon marked this conversation as resolved.
Show resolved Hide resolved
// Load the preload scripts.
for (const preloadScript of preloadScripts) {
for (const { preloadPath: preloadScript } of preloadScripts) {
try {
Module._load(preloadScript);
} catch (error) {
Expand Down
10 changes: 9 additions & 1 deletion spec-main/api-browser-window-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3263,7 +3263,15 @@ describe('BrowserWindow module', () => {
});
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: { show: false, webPreferences: { contextIsolation: false, webviewTag: true, nodeIntegrationInSubFrames: true } }
overrideBrowserWindowOptions: {
show: false,
webPreferences: {
contextIsolation: false,
webviewTag: true,
nodeIntegrationInSubFrames: true,
preload
}
}
}));

const webviewLoaded = emittedOnce(ipcMain, 'webview-loaded');
Expand Down