Skip to content

Commit

Permalink
add new event listeners to get request starting
Browse files Browse the repository at this point in the history
  • Loading branch information
Warren Day authored and Warren Day committed Jan 15, 2024
1 parent bfb8e7c commit e30f55b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"128": "icon.png"
},
"manifest_version": 3,
"permissions": [],
"permissions": ["webRequest"],
"host_permissions": ["<all_urls>"],
"devtools_page": "devtools/devtools.html",
"content_scripts": [
{
Expand Down
32 changes: 32 additions & 0 deletions src/services/networkMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ export const getHAR = async (): Promise<chrome.devtools.network.HARLog> => {
})
}

export const onBeforeRequest = (
cb: (e: chrome.webRequest.WebRequestBodyDetails) => void
) => {
const chrome = chromeProvider()

chrome.webRequest.onBeforeRequest.addListener(cb, { urls: ["<all_urls>"] }, [
"requestBody",
])
return () => {
chrome.webRequest.onBeforeRequest.removeListener(cb)
}
}

export const onBeforeSendHeaders = (
cb: (e: chrome.webRequest.WebRequestHeadersDetails) => void
) => {
const chrome = chromeProvider()

chrome.webRequest.onBeforeSendHeaders.addListener(
cb,
{ urls: ["<all_urls>"] },
["requestHeaders"]
)
return () => {
chrome.webRequest.onBeforeSendHeaders.removeListener(cb)
}
}

export const onRequestFinished = (
cb: (e: chrome.devtools.network.Request) => void
) => {
Expand All @@ -27,3 +55,7 @@ export const onNavigate = (cb: () => void) => {
chrome.devtools.network.onNavigated.removeListener(cb)
}
}

// Can I get request body in webrequest event?
// If so, can just match on headers, method, body.
// Just associate first response where match, is found.

0 comments on commit e30f55b

Please sign in to comment.