Skip to content

Commit bcdba36

Browse files
🔧 migrate the developer-extension to wxt
1 parent 0a92a6d commit bcdba36

26 files changed

+2743
-1232
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ browserstack.err
1111
package.tgz
1212
docs/
1313
*.tsbuildinfo
14+
/developer-extension/.output
15+
/developer-extension/.wxt
1416

1517
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
1618
.pnp.*

‎.prettierignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ developer-extension/dist
88
test/**/dist
99
yarn.lock
1010
/docs
11+
/developer-extension/.output
12+
/developer-extension/.wxt

‎LICENSE-3rdparty.csv‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ dev,@types/node-forge,MIT,Copyright Microsoft Corporation
2424
dev,@types/pako,MIT,Copyright Microsoft Corporation
2525
dev,@types/react,MIT,Copyright Microsoft Corporation
2626
dev,@types/react-dom,MIT,Copyright Microsoft Corporation
27-
dev,@webextension-toolbox/webpack-webextension-plugin,MIT,Copyright 2018 Henrik Wenz ([email protected])
27+
dev,@wxt-dev/module-react,MIT,Copyright (c) 2023 Aaron
2828
dev,ajv,MIT,Copyright 2015-2017 Evgeny Poberezkin
2929
dev,browserstack-local,MIT,Copyright 2016 BrowserStack
3030
dev,chrome-webstore-upload,MIT,Copyright Federico Brigante <[email protected]> (https://fregante.com), 2020 Andrew Levine
3131
dev,connect-busboy,MIT,Copyright Brian White
32-
dev,copy-webpack-plugin,MIT,Copyright JS Foundation and other contributors
3332
dev,cors,MIT,Copyright 2013 Troy Goode
34-
dev,css-loader,MIT,Copyright JS Foundation and other contributors
3533
dev,emoji-name-map,MIT,Copyright 2016-19 Ionică Bizău <[email protected]> (https://ionicabizau.net)
3634
dev,eslint,MIT,Copyright JS Foundation and other contributors
3735
dev,eslint-module-utils,MIT,Copyright (c) 2015 Ben Mosher
@@ -60,7 +58,6 @@ dev,pako,MIT,(C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
6058
dev,prettier,MIT,Copyright James Long and contributors
6159
dev,puppeteer,Apache-2.0,Copyright 2017 Google Inc.
6260
dev,react-router-dom,MIT,Copyright (c) React Training LLC 2015-2019 Copyright (c) Remix Software Inc. 2020-2021 Copyright (c) Shopify Inc. 2022-2023
63-
dev,style-loader,MIT,Copyright JS Foundation and other contributors
6461
dev,terser-webpack-plugin,MIT,Copyright JS Foundation and other contributors
6562
dev,ts-loader,MIT,Copyright 2015 TypeStrong
6663
dev,ts-node,MIT,Copyright 2014 Blake Embrey
@@ -72,10 +69,6 @@ dev,webpack-cli,MIT,Copyright JS Foundation and other contributors
7269
dev,webpack-dev-middleware,MIT,Copyright JS Foundation and other contributors
7370
dev,@swc/core,Apache-2.0,Copyright (c) SWC Contributors
7471
dev,swc-loader,MIT,Copyright (c) SWC Contributors
75-
dev,@pmmmwh/react-refresh-webpack-plugin,MIT,Copyright (c) Michael Mok
76-
dev,@types/webpack-env,MIT,Copyright Microsoft Corporation
77-
dev,react-refresh,MIT,Copyright (c) Facebook, Inc. and its affiliates.
78-
dev,react-refresh-typescript,MIT,Copyright (c) Piotr Monwid-Olechnowicz
79-
dev,webpack-dev-server,MIT,Copyright JS Foundation and other contributors
8072
dev,http-server,MIT,Copyright http-party contributors
8173
dev,react-router,MIT,Copyright (c) React Training LLC 2015-2019 Copyright (c) Remix Software Inc. 2020-2021 Copyright (c) Shopify Inc. 2022-2023
74+
dev,wxt,MIT,Copyright (c) 2023 Aaron

‎developer-extension/.gitignore‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎developer-extension/manifest.json‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎developer-extension/package.json‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,15 @@
33
"version": "6.24.0",
44
"private": true,
55
"scripts": {
6-
"build": "rm -rf dist && webpack --disable-interpret --mode production",
7-
"dev": "rm -rf dist && webpack --disable-interpret --mode development && webpack serve --disable-interpret --mode development --config-name=panel --hot"
6+
"build": "wxt build",
7+
"dev": "wxt"
88
},
99
"devDependencies": {
10-
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.0",
1110
"@types/chrome": "0.1.24",
1211
"@types/react": "19.2.2",
1312
"@types/react-dom": "19.2.2",
14-
"@types/webpack-env": "^1.18.4",
15-
"@webextension-toolbox/webpack-webextension-plugin": "3.3.1",
16-
"copy-webpack-plugin": "13.0.1",
17-
"css-loader": "7.1.2",
18-
"html-webpack-plugin": "5.6.4",
19-
"react-refresh": "^0.18.0",
20-
"react-refresh-typescript": "^2.0.9",
21-
"style-loader": "4.0.0",
22-
"typescript": "5.9.3",
23-
"webpack": "5.102.1",
24-
"webpack-cli": "^6.0.0",
25-
"webpack-dev-server": "^5.0.4"
13+
"@wxt-dev/module-react": "1.1.5",
14+
"typescript": "5.9.3"
2615
},
2716
"dependencies": {
2817
"@datadog/browser-core": "workspace:*",
@@ -33,7 +22,8 @@
3322
"@tabler/icons-react": "3.35.0",
3423
"clsx": "2.1.1",
3524
"react": "19.2.0",
36-
"react-dom": "19.2.0"
25+
"react-dom": "19.2.0",
26+
"wxt": "0.20.11"
3727
},
3828
"volta": {
3929
"extends": "../package.json"

‎developer-extension/src/background/domain/messageRelay.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ const CONTENT_SCRIPTS: Array<{
3030
{
3131
id: 'browser-sdk-content-script-main',
3232
world: chrome.scripting.ExecutionWorld.MAIN,
33-
file: './content-script-main.js',
33+
file: './contentScriptMain.js',
3434
},
3535
{
3636
id: 'browser-sdk-content-script-isolated',
3737
world: chrome.scripting.ExecutionWorld.ISOLATED,
38-
file: './content-script-isolated.js',
38+
file: './contentScriptIsolated.js',
3939
},
4040
]
4141

‎developer-extension/src/content-scripts/isolated.ts‎

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,39 @@
33
import { isDisconnectError } from '../common/isDisconnectError'
44
import { createLogger } from '../common/logger'
55

6-
const logger = createLogger('content-script-isolated')
6+
export function main() {
7+
const logger = createLogger('content-script-isolated')
78

8-
interface IsolatedWindow {
9-
unregisterIsolatedScript?(): void
10-
}
9+
interface IsolatedWindow {
10+
unregisterIsolatedScript?(): void
11+
}
1112

12-
const isolatedWindow = window as IsolatedWindow
13+
const isolatedWindow = window as IsolatedWindow
1314

14-
// Unregister any callback from a previously injected isolated content script
15-
if (isolatedWindow.unregisterIsolatedScript) {
16-
isolatedWindow.unregisterIsolatedScript()
17-
}
18-
// Register the new callback
19-
window.addEventListener('__ddBrowserSdkMessage', browserSdkMessageListener)
15+
// Unregister any callback from a previously injected isolated content script
16+
if (isolatedWindow.unregisterIsolatedScript) {
17+
isolatedWindow.unregisterIsolatedScript()
18+
}
19+
// Register the new callback
20+
window.addEventListener('__ddBrowserSdkMessage', browserSdkMessageListener)
2021

21-
isolatedWindow.unregisterIsolatedScript = () => {
22-
window.removeEventListener('__ddBrowserSdkMessage', browserSdkMessageListener)
23-
}
22+
isolatedWindow.unregisterIsolatedScript = () => {
23+
window.removeEventListener('__ddBrowserSdkMessage', browserSdkMessageListener)
24+
}
2425

25-
// Listen to events from the "main" content script and relays them to the background script via the
26-
// webextension API.
27-
function browserSdkMessageListener(event: unknown) {
28-
const detail = (event as CustomEvent).detail
26+
// Listen to events from the "main" content script and relays them to the background script via the
27+
// webextension API.
28+
function browserSdkMessageListener(event: unknown) {
29+
const detail = (event as CustomEvent).detail
2930

30-
try {
31-
chrome.runtime.sendMessage(detail).catch((error) => logger.error('Failed to send message:', error))
32-
} catch (error) {
33-
// Ignore errors when the background script is unloaded, as this is expected to happen sometimes and we
34-
// don't want to spam the console in this case.
35-
if (!isDisconnectError(error)) {
36-
logger.error('Failed to send message:', error)
31+
try {
32+
chrome.runtime.sendMessage(detail).catch((error) => logger.error('Failed to send message:', error))
33+
} catch (error) {
34+
// Ignore errors when the background script is unloaded, as this is expected to happen sometimes and we
35+
// don't want to spam the console in this case.
36+
if (!isDisconnectError(error)) {
37+
logger.error('Failed to send message:', error)
38+
}
3739
}
3840
}
3941
}

‎developer-extension/src/content-scripts/main.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface SdkPublicApi {
1515
[key: string]: (...args: any[]) => unknown
1616
}
1717

18-
function main() {
18+
export function main() {
1919
// Prevent multiple executions when the devetools are reconnecting
2020
if (window.__ddBrowserSdkExtensionCallback) {
2121
return
@@ -54,8 +54,6 @@ function main() {
5454
}
5555
}
5656

57-
main()
58-
5957
function sendEventsToExtension() {
6058
// This script is executed in the "main" execution world, the same world as the webpage. Thus, it
6159
// can define a global callback variable to listen to SDK events.

0 commit comments

Comments
 (0)