Skip to content

Commit

Permalink
Fix websocket URL for non-localhost debugger instances. (duckduckgo#2526
Browse files Browse the repository at this point in the history
)

* Fix websocket URL for non-localhost debugger instances.

* Use URL.protocol setting

* Check for NaN for provided tabId
  • Loading branch information
sammacbeth committed May 5, 2024
1 parent fa171ee commit b5ec76c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions shared/js/background/components/debugger-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ export default class DebuggerConnection {
this.configURLOverride = configURLOverride
this.debuggerConnectionEnabled = debuggerConnection
if (this.configURLOverride && this.debuggerConnectionEnabled) {
const url = new URL('./debugger/extension', this.configURLOverride.replace(/https?:/, 'ws:'))
const url = new URL('./debugger/extension', this.configURLOverride)
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'
url.searchParams.append('browserName', getBrowserName())
url.searchParams.append('version', getExtensionVersion())
let lastUpdate = 0
this.socket = new WebSocket(url.href)
this.socket.addEventListener('message', (event) => {
const { messageType, payload } = JSON.parse(event.data)
console.log('debugger message', event.data)
if (messageType === 'status') {
if (payload.lastBuild > lastUpdate) {
lastUpdate = payload.lastBuild
this.tds.config.checkForUpdates(true)
}
} else if (messageType === 'subscribe') {
const { tabId } = payload
if (!this.subscribedTabs.has(tabId)) {
const tabId = parseInt(payload.tabId, 10)
if (!this.subscribedTabs.has(tabId) && !isNaN(tabId)) {
this.subscribedTabs.add(tabId)
this.forwardDebugMessagesForTab(tabId)
}
Expand Down

0 comments on commit b5ec76c

Please sign in to comment.