Skip to content

Fix webpack issue when enable sandbox #246

@abbie982

Description

@abbie982

To enable the sandbox in browser webview of desktop app, we need to change the webpack config for preload.js in:/packages/injected/webpack.config.cjs as follow:

const nativeConfig = merge(commonConfig, {
  target: 'electron-preload',
  entry: {
    injectedDesktop: './src/injectedDesktop.ts',
  },
});

to the new one:

const nativeConfig = merge(commonConfig, {
  target: 'web',
  entry: {
    injectedDesktop: './src/injectedDesktop.ts',
  },
  externals: {
    electron: 'commonjs electron', // 将 Electron 标记为外部模块
  },
});

Otherwise, there will be a issue caused by import electron in preload.js, because of the limitation of sandbox such as limitation in require.

PR related to this is here:Change preload.js webpack config to support sandbox

PR related to app's sandbox config is here:Enable sandbox in browser's webview of desktop

#245

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions