Skip to content

Commit

Permalink
update: queryForDevtoolTabs for custom devtools urls
Browse files Browse the repository at this point in the history
  • Loading branch information
june07 committed Aug 5, 2024
1 parent dc87875 commit fc0cb5e
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,47 @@ async function queryForDevtoolTabs(host, port) {
`${settings.DEVTOOLS_SCHEME}*/*${host}:${port}*`,
`${settings.DEVTOOLS_SCHEME}*/*${host}/ws/${port}*`,

`https://devtools-frontend.june07.com/*${host}:${port}*`,
`https://devtools-frontend.june07.com/*${host}/ws/${port}*`,

`https://chrome-devtools-frontend.june07.com/*${host}:${port}*`,
`https://chrome-devtools-frontend.june07.com/*${host}/ws/${port}*`,

`https://chrome-devtools-frontend.appspot.com/*${host}:${port}*`,
`https://chrome-devtools-frontend.appspot.com/*${host}/ws/${port}*`
]
if (settings.localDevtools && settings.localDevtoolsOptions[settings.localDevtoolsOptionsSelectedIndex].url.match(reDevtoolsURL)) {
const devtoolsURL = new URL(settings.localDevtoolsOptions[settings.localDevtoolsOptionsSelectedIndex].url)
const customDevToolsPatterns = [
`${devtoolsURL.origin}/*${host}:${port}*`,
`${devtoolsURL.origin}/*${host}/ws/${port}*`
]

devtoolsLocalPatterns.push(...customDevToolsPatterns)
}
url = devtoolsLocalPatterns
} else {
const { cid } = remoteMetadata

if (cid) {
devtoolsRemotePatterns = [
`${settings.DEVTOOLS_SCHEME}*/*/${cid}/*`,
`https://devtools-frontend.june07.com/*/${cid}/*`,
`https://chrome-devtools-frontend.june07.com/*/${cid}/*`,
`https://chrome-devtools-frontend.appspot.com/*/${cid}/*`,
]
url = devtoolsRemotePatterns
} else {
url = [
devtoolsRemotePatterns = [
`${settings.DEVTOOLS_SCHEME}*/*`
]
}
if (settings.localDevtools && settings.localDevtoolsOptions[settings.localDevtoolsOptionsSelectedIndex].url.match(reDevtoolsURL)) {
const devtoolsURL = new URL(settings.localDevtoolsOptions[settings.localDevtoolsOptionsSelectedIndex].url)
const customDevToolsPattern = `${devtoolsURL.origin}/*/${cid}/*`

devtoolsRemotePatterns.push(customDevToolsPattern)
}
url = devtoolsRemotePatterns
}
const tabs = await chrome.tabs.query({ url })
return tabs.map(tab => ({ ...tab, socket: { host, port } }))
Expand Down Expand Up @@ -775,7 +794,7 @@ chrome.runtime.onStartup.addListener(() => {
chrome.tabs.onUpdated.addListener(async function chromeTabsChangedEvent(tabId, { status }, tab) {
const { toolsWindow } = await chrome.storage.local.get(['toolsWindow'])

if (toolsWindow.id === tab.windowId && status === 'complete') {
if (toolsWindow?.id === tab.windowId && status === 'complete') {
let updatedToolsWindow = await chrome.windows.get(toolsWindow.id, { populate: true })
const tabIndex = updatedToolsWindow.tabs.findIndex(tab => tab.id === tabId)
if (tabIndex !== -1) {
Expand All @@ -792,7 +811,7 @@ chrome.tabs.onCreated.addListener(async function chromeTabsCreatedEvent(tab) {
settings.auto = false
}

if (toolsWindow.id === tab.windowId) {
if (toolsWindow?.id === tab.windowId) {
const updatedToolsWindow = await chrome.windows.get(toolsWindow.id, { populate: true })
await chrome.storage.local.set({ 'toolsWindow': updatedToolsWindow })
}
Expand Down

0 comments on commit fc0cb5e

Please sign in to comment.