2

I am writing a plugin for Chrome (manifest v3). It should create a WebSocket connection between the Service Worker and the Chrome Debugger, so that I can control a page with puppeteer.

const browserDebugger = await (
await fetch(http://localhost:9223/json/version, { mode: "no-cors" })
).json();
const debuggerURL = browserDebugger.webSocketDebuggerUrl;
const chromeWebsocket = new WebSocket(debuggerURL);

I am getting the following error in the last line:

WebSocket connection to 'ws://localhost:9223/devtools/browser/2cd7eac1-a1e0-41ed-9eac-8ba8d0befc9e' failed: Error during WebSocket handshake: Unexpected response code: 403

manifest.json:

{
  "manifest_version": 3,
  ....
  "content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'self'; connect-src http://localhost:9223/ ws://localhost:9223/ http://localhost:4821/ ws://localhost:4821/"
  },
  "host_permissions": [
    "http://*/*",
    "https://*/*",
    "http://localhost:4821/",
    "http://localhost:9223/"
  ],
  "permissions": [
    "debugger",
    "tabs",
  ]
}

What is wrong?

  • Try debugging via `chrome://net-export` – wOxxOm Mar 21 '23 at 17:25
  • @wOxxOm I don't understand, how I can use this information. It's just a json without any data about error: ```{ "params": { "message": "Error during WebSocket handshake: Unexpected response code: 403", "net_error": -2 }, "phase": 0, "source": { "id": 336, "start_time": "1192068373", "type": 1 }, "time": "1192068374", "type": 511 },``` – Igor Savchenko Mar 22 '23 at 11:06
  • 2
    Solution was to add `--remote-allow-origins=*` to start parameters of the chrome. – Igor Savchenko Mar 27 '23 at 11:50

0 Answers0