Skip to content

Commit

Permalink
feat: Allow passing preferences to chrome, enable dev mode and conten…
Browse files Browse the repository at this point in the history
…t script sourcemaps by default
  • Loading branch information
aklinker1 committed Jan 29, 2024
1 parent 39b76d3 commit 731dae7
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"rollup-plugin-visualizer": "^5.9.2",
"unimport": "^3.4.0",
"vite": "^5.0.12",
"web-ext-run": "^0.1.2",
"web-ext-run": "^0.2.0",
"webextension-polyfill": "^0.10.0",
"zip-dir": "^2.0.0"
},
Expand Down
46 changes: 36 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/core/runners/web-ext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { WebExtRunInstance } from 'web-ext-run';
import { ExtensionRunner } from '~/types';
import { formatDuration } from '../utils/time';
import defu from 'defu';

/**
* Create an `ExtensionRunner` backed by `web-ext`.
Expand Down Expand Up @@ -40,6 +41,10 @@ export function createWebExtRunner(): ExtensionRunner {
: {
chromiumBinary: wxtUserConfig?.binaries?.[config.browser],
chromiumProfile: wxtUserConfig?.chromiumProfile,
chromiumPref: defu(
wxtUserConfig?.chromiumPref,
DEFAULT_CHROMIUM_PREFS,
),

Check warning on line 47 in src/core/runners/web-ext.ts

View check run for this annotation

Codecov / codecov/patch

src/core/runners/web-ext.ts#L44-L47

Added lines #L44 - L47 were not covered by tests
args: wxtUserConfig?.chromiumArgs,
}),
};
Expand Down Expand Up @@ -75,3 +80,14 @@ export function createWebExtRunner(): ExtensionRunner {
// https://github.com/mozilla/web-ext/blob/e37e60a2738478f512f1255c537133321f301771/src/util/logger.js#L12
const WARN_LOG_LEVEL = 40;
const ERROR_LOG_LEVEL = 50;

const DEFAULT_CHROMIUM_PREFS = {
devtools: {
synced_preferences_sync_disabled: {
// Remove content scripts from sourcemap debugger ignore list so stack traces
// and log locations show up properly, see:
// https://github.com/wxt-dev/wxt/issues/236#issuecomment-1915364520
skipContentScripts: false,
},
},
};
27 changes: 27 additions & 0 deletions src/types/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,33 @@ export interface ExtensionRunnerConfig {
* @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#chromium-profile
*/
chromiumProfile?: string;
/**
* An map of chrome preferences from https://chromium.googlesource.com/chromium/src/+/main/chrome/common/pref_names.h
*
* @example
* // change your downloads directory
* {
* download: {
* default_directory: "/my/custom/dir",
* },
* }
*
* @default
* // Enable dev mode and allow content script sourcemaps
* {
* devtools: {
* synced_preferences_sync_disabled: {
* skipContentScripts: false,
* },
* }
* extensions: {
* ui: {
* developer_mode: true,
* },
* }
* }
*/
chromiumPref?: string;
/**
* @see https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#pref
*/
Expand Down

0 comments on commit 731dae7

Please sign in to comment.