-
Notifications
You must be signed in to change notification settings - Fork 144
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
✨ [RUMF-1396] migrate extension to manifest v3 #1828
Changes from all commits
670bf54
6bd09cf
ef59bd2
c866c1b
61f84fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ dev,@wdio/junit-reporter,MIT,Copyright (c) OpenJS Foundation and other contribut | |
dev,@wdio/local-runner,MIT,Copyright JS Foundation and other contributors | ||
dev,@wdio/selenium-standalone-service,MIT,Copyright JS Foundation and other contributors | ||
dev,@wdio/spec-reporter,MIT,Copyright JS Foundation and other contributors | ||
dev,@webextension-toolbox/webpack-webextension-plugin,MIT,Copyright 2018 Henrik Wenz ([email protected]) | ||
dev,ajv,MIT,Copyright 2015-2017 Evgeny Poberezkin | ||
dev,browserstack-local,MIT,Copyright 2016 BrowserStack | ||
dev,connect-busboy,MIT,Copyright Brian White | ||
|
@@ -77,5 +78,4 @@ dev,webdriverio,MIT,Copyright JS Foundation and other contributors | |
dev,webpack,MIT,Copyright JS Foundation and other contributors | ||
dev,webpack-cli,MIT,Copyright JS Foundation and other contributors | ||
dev,webpack-dev-middleware,MIT,Copyright JS Foundation and other contributors | ||
dev,webpack-webextension-plugin,MIT,Copyright 2018 Henrik Wenz ([email protected]) | ||
dev,node-fetch,MIT,Copyright 2016-2020 Node Fetch Team |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
{ | ||
"manifest_version": 2, | ||
"manifest_version": 3, | ||
"name": "Datadog Browser SDK developer extension", | ||
"permissions": ["<all_urls>", "tabs", "webRequest", "webRequestBlocking", "storage", "browsingData"], | ||
"permissions": ["webRequest", "storage", "browsingData", "declarativeNetRequest"], | ||
"host_permissions": ["<all_urls>"], | ||
"icons": { | ||
"256": "icon.png" | ||
}, | ||
"background": { | ||
"scripts": ["background.js"], | ||
"persistent": true | ||
"service_worker": "background.js", | ||
"type": "module" | ||
}, | ||
"devtools_page": "devtools.html" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
export const DEV_LOGS_URL = 'http://localhost:8080/datadog-logs.js' | ||
export const DEV_RUM_URL = 'http://localhost:8080/datadog-rum.js' | ||
export const DEV_RUM_SLIM_URL = 'http://localhost:8080/datadog-rum-slim.js' | ||
|
||
export const INTAKE_DOMAINS = [ | ||
'browser-intake-datadoghq.com', | ||
'browser-intake-datadoghq.eu', | ||
'browser-intake-ddog-gov.com', | ||
'browser-intake-us3-datadoghq.com', | ||
'browser-intake-us5-datadoghq.com', | ||
...['com', 'eu'].flatMap((tld) => [ | ||
`public-trace-http-intake.logs.datadoghq.${tld}`, | ||
`rum-http-intake.logs.datadoghq.${tld}`, | ||
`browser-http-intake.logs.datadoghq.${tld}`, | ||
]), | ||
] |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { listenAction } from '../actions' | ||
import { DEV_LOGS_URL } from '../constants' | ||
import { setStore } from '../store' | ||
|
||
listenAction('getStore', () => { | ||
refreshDevServerStatus().catch((error) => | ||
console.error('refreshDevServerStatus: Unexpected error while refreshing dev server status:', error) | ||
) | ||
}) | ||
|
||
async function refreshDevServerStatus() { | ||
const timeoutId = setTimeout(() => setStore({ devServerStatus: 'checking' }), 500) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you not want to phase out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I want but not in this PR :) I only moved this function in another file. |
||
let isAvailable = false | ||
try { | ||
const response = await fetch(DEV_LOGS_URL, { method: 'HEAD' }) | ||
isAvailable = response.status === 200 | ||
} catch { | ||
// The request can fail if nothing is listening on the URL port. In this case, consider the dev | ||
// server 'unavailable'. | ||
} | ||
clearTimeout(timeoutId) | ||
setStore({ devServerStatus: isAvailable ? 'available' : 'unavailable' }) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { listenAction } from '../actions' | ||
import { DEV_LOGS_URL, DEV_RUM_SLIM_URL, DEV_RUM_URL, INTAKE_DOMAINS } from '../constants' | ||
import { store } from '../store' | ||
|
||
listenAction('setStore', (newStore) => { | ||
if ('useDevBundles' in newStore || 'useRumSlim' in newStore || 'blockIntakeRequests' in newStore) { | ||
void chrome.browsingData.removeCache({}) | ||
syncRules() | ||
} | ||
}) | ||
|
||
function syncRules() { | ||
console.log('syncRules: Syncing rules') | ||
chrome.declarativeNetRequest | ||
.getSessionRules() | ||
.then((existingRules) => | ||
chrome.declarativeNetRequest.updateSessionRules({ | ||
removeRuleIds: existingRules.map((rule) => rule.id), | ||
addRules: getRules(), | ||
}) | ||
) | ||
.catch((error) => console.error('syncRules: Error while syncing rules:', error)) | ||
} | ||
|
||
function getRules() { | ||
const rules: chrome.declarativeNetRequest.Rule[] = [] | ||
let id = 1 | ||
|
||
if (store.useDevBundles) { | ||
const devRumUrl = store.useRumSlim ? DEV_RUM_SLIM_URL : DEV_RUM_URL | ||
console.log('syncRules: add redirect to dev bundles rules') | ||
rules.push( | ||
createRedirectRule(id++, /^https:\/\/.*\/datadog-rum(-v\d|canary|staging)?\.js$/, { url: devRumUrl }), | ||
createRedirectRule(id++, /^https:\/\/.*\/datadog-rum-slim(-v\d|canary|staging)?\.js$/, { url: DEV_RUM_SLIM_URL }), | ||
createRedirectRule(id++, /^https:\/\/.*\/datadog-logs(-v\d|canary|staging)?\.js$/, { url: DEV_LOGS_URL }), | ||
createRedirectRule(id++, 'https://localhost:8443/static/datadog-rum-hotdog.js', { url: devRumUrl }) | ||
) | ||
} else if (store.useRumSlim) { | ||
console.log('syncRules: add redirect to rum slim rule') | ||
rules.push(createRedirectRule(id++, /^(https:\/\/.*\/datadog-rum)(-slim)?/, { regexSubstitution: '\\1-slim' })) | ||
} | ||
|
||
if (store.blockIntakeRequests) { | ||
console.log('syncRules: add block intake rules') | ||
for (const intakeDomain of INTAKE_DOMAINS) { | ||
rules.push({ | ||
id: id++, | ||
condition: { urlFilter: `||${intakeDomain}` }, | ||
action: { | ||
type: chrome.declarativeNetRequest.RuleActionType.BLOCK, | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
return rules | ||
} | ||
|
||
function createRedirectRule( | ||
id: number, | ||
filter: RegExp | string, | ||
redirect: chrome.declarativeNetRequest.Redirect | ||
): chrome.declarativeNetRequest.Rule { | ||
return { | ||
id, | ||
action: { | ||
type: chrome.declarativeNetRequest.RuleActionType.REDIRECT, | ||
redirect, | ||
}, | ||
condition: typeof filter === 'string' ? { urlFilter: `|${filter}|` } : { regexFilter: filter.source }, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import './domain/replaceBundles' | ||
import './domain/blockIntakeRequests' | ||
import './domain/refreshDevServerStatus' | ||
import './domain/syncRules' |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { createListenAction, createSendAction } from '../common/actions' | ||
import type { BackgroundActions, PopupActions } from '../common/types' | ||
|
||
export const sendAction = createSendAction<BackgroundActions>() | ||
const { sendAction, setOnDisconnect } = createSendAction<BackgroundActions>() | ||
export { sendAction, setOnDisconnect } | ||
export const listenAction = createListenAction<PopupActions>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!