From 731dae7d74159608afe93038973eb8f6c256dd99 Mon Sep 17 00:00:00 2001 From: Aaron Klinker Date: Mon, 29 Jan 2024 13:47:58 -0600 Subject: [PATCH] feat: Allow passing preferences to chrome, enable dev mode and content script sourcemaps by default --- package.json | 2 +- pnpm-lock.yaml | 46 +++++++++++++++++++++++++++++-------- src/core/runners/web-ext.ts | 16 +++++++++++++ src/types/external.ts | 27 ++++++++++++++++++++++ 4 files changed, 80 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index a6f8c7a16..540953a22 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7d03b61f9..7e31d93a4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,8 +105,8 @@ importers: specifier: ^5.0.12 version: 5.0.12(@types/node@20.10.3)(sass@1.69.5) web-ext-run: - specifier: ^0.1.2 - version: 0.1.2 + specifier: ^0.2.0 + version: 0.2.0 webextension-polyfill: specifier: ^0.10.0 version: 0.10.0 @@ -1815,15 +1815,15 @@ packages: engines: {node: '>=10'} dev: false - /chrome-launcher@0.15.1: - resolution: {integrity: sha512-UugC8u59/w2AyX5sHLZUHoxBAiSiunUhZa3zZwMH6zPVis0C3dDKiRWyUGIo14tTbZHGVviWxv3PQWZ7taZ4fg==} + /chrome-launcher@1.1.0: + resolution: {integrity: sha512-rJYWeEAERwWIr3c3mEVXwNiODPEdMRlRxHc47B1qHPOolHZnkj7rMv1QSUfPoG6MgatWj5AxSpnKKR4QEwEQIQ==} engines: {node: '>=12.13.0'} hasBin: true dependencies: '@types/node': 20.10.3 escape-string-regexp: 4.0.0 is-wsl: 2.2.0 - lighthouse-logger: 1.4.2 + lighthouse-logger: 2.0.1 transitivePeerDependencies: - supports-color dev: false @@ -2993,6 +2993,18 @@ packages: engines: {node: '>=8'} dev: false + /is-plain-object@2.0.4: + resolution: {integrity: sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==} + engines: {node: '>=0.10.0'} + dependencies: + isobject: 3.0.1 + dev: false + + /is-primitive@3.0.1: + resolution: {integrity: sha512-GljRxhWvlCNRfZyORiH77FwdFwGcMO620o37EOYC0ORWdq+WYNVqW0w2Juzew4M+L81l6/QS3t5gkkihyRqv9w==} + engines: {node: '>=0.10.0'} + dev: false + /is-regex@1.1.4: resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} engines: {node: '>= 0.4'} @@ -3091,6 +3103,11 @@ packages: /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + /isobject@3.0.1: + resolution: {integrity: sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==} + engines: {node: '>=0.10.0'} + dev: false + /istanbul-lib-coverage@3.2.2: resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} engines: {node: '>=8'} @@ -3200,8 +3217,8 @@ packages: immediate: 3.0.6 dev: false - /lighthouse-logger@1.4.2: - resolution: {integrity: sha512-gPWxznF6TKmUHrOQjlVo2UbaL2EJ71mb2CCeRs/2qBpi4L/g4LUVc9+3lKQ6DTUZwJswfM7ainGrLO1+fOqa2g==} + /lighthouse-logger@2.0.1: + resolution: {integrity: sha512-ioBrW3s2i97noEmnXxmUq7cjIcVRjT5HBpAYy8zE11CxU9HqlWHHeRxfeN1tn8F7OEMVPIC9x1f8t3Z7US9ehQ==} dependencies: debug: 2.6.9 marky: 1.2.5 @@ -4242,6 +4259,14 @@ packages: dependencies: lru-cache: 6.0.0 + /set-value@4.1.0: + resolution: {integrity: sha512-zTEg4HL0RwVrqcWs3ztF+x1vkxfm0lP+MQQFPiMJTKVceBwEV0A569Ou8l9IYQG8jOZdMVI1hGsc0tmeD2o/Lw==} + engines: {node: '>=11.0'} + dependencies: + is-plain-object: 2.0.4 + is-primitive: 3.0.1 + dev: false + /setimmediate@1.0.5: resolution: {integrity: sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==} dev: false @@ -5255,14 +5280,14 @@ packages: graceful-fs: 4.2.11 dev: false - /web-ext-run@0.1.2: - resolution: {integrity: sha512-VygO7lg10keonbku5Lbi21zEz1k91odkW+c6YB5DGb+mITcRMVM2zr/tJ+Suh6wxNUOOFNbinoqDlSUWdxt6YQ==} + /web-ext-run@0.2.0: + resolution: {integrity: sha512-lAm05ELMr2WDPniyaHmyuPK0rb9tsftC8f/Ui5AQvlU6F3LqoBDfyzOaaUVQrLxtm4F5oax8AHPWswf/XjZzAg==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} dependencies: '@babel/runtime': 7.23.9 '@devicefarmer/adbkit': 3.2.6 bunyan: 1.8.15 - chrome-launcher: 0.15.1 + chrome-launcher: 1.1.0 debounce: 1.2.1 es6-error: 4.1.1 firefox-profile: 4.5.0 @@ -5274,6 +5299,7 @@ packages: node-notifier: 10.0.1 parse-json: 7.1.1 promise-toolbox: 0.21.0 + set-value: 4.1.0 source-map-support: 0.5.21 strip-bom: 5.0.0 strip-json-comments: 5.0.1 diff --git a/src/core/runners/web-ext.ts b/src/core/runners/web-ext.ts index b415ec3d5..72bf3bcd2 100644 --- a/src/core/runners/web-ext.ts +++ b/src/core/runners/web-ext.ts @@ -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`. @@ -40,6 +41,10 @@ export function createWebExtRunner(): ExtensionRunner { : { chromiumBinary: wxtUserConfig?.binaries?.[config.browser], chromiumProfile: wxtUserConfig?.chromiumProfile, + chromiumPref: defu( + wxtUserConfig?.chromiumPref, + DEFAULT_CHROMIUM_PREFS, + ), args: wxtUserConfig?.chromiumArgs, }), }; @@ -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, + }, + }, +}; diff --git a/src/types/external.ts b/src/types/external.ts index b1adff430..271aed318 100644 --- a/src/types/external.ts +++ b/src/types/external.ts @@ -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 */