How to attach to a remote debugging target using chrome.debugger.attach()

245 views
Skip to first unread message

Abhishek Ghosh

unread,
Jun 7, 2024, 5:54:04 AMJun 7
to Chromium Extensions
Hello everyone! 

I am trying to create a chrome devtools extension where I can debug code in a normal service worker of a website (not extension service worker). To do this, I am using chrome.debugger APIs in my extension to attach to the website's service worker target and executing commands (like Runtime.evaluate etc.).

I also want to be able to do the same for remote debugging targets, i.e. when website is open on Chrome for Android on a phone, which I have connected with my laptop using a USB cable to do remote debugging using desktop chrome's dev tools (a common practice). In this case, I am trying to get the dev tools extension (installed on desktop chrome) to be able to connect to the service worker target running remotely on the android phone's chrome browser, so that I can continue debugging it. But I am not able to find a way to connect using chrome.debugger.* APIs to connect to this remote target. The target seems to be missing in the list of chrome.debugger.getTargets(), and tabId seems to be null. Even if I snoop the remote target (see below) and try to call .attach() it doesn't work.

I've tried enabling device discovery, remote targets and see such remote targets pop up generally in chrome's own discovery somewhere in the form of <devicename>:chrome_devtools_remote:<targetid> or when explicitly enabling port forwarding, something like localhost:9222:<targetid> but I cant seem to find a way to connect from my extension (it always fails with a "runtime.lastError: No target with given id ..." message, even though in general I can see the browser itself is able to connect to it and inspect (naturally!). I've been snooping around the Protocol Monitor in Chrome quite a bit in the hope of gaining some clue but so far, haven't really been able to crack this mystery :( 

Is this even possible, or am I even going in the right direction? I am fairly new to chrome extensions and CDP, so any guidance, alternate ideas, direction, hacks or workaround are highly appreciated! 

Thank you so much for your time!

- Abhishek

Oliver Dunk

unread,
Jun 7, 2024, 6:30:27 AMJun 7
to Abhishek Ghosh, Chromium Extensions
Hi Abhishek,

It looks like a member of the team already replied here: https://groups.google.com/g/chrome-debugging-protocol/c/t-3sJKPb_F4/m/AmV7_d76AAAJ

Hope that helps,
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/7a0307b6-8e58-4415-81a2-64441cfa4320n%40chromium.org.

Abhishek Ghosh

unread,
Jun 7, 2024, 6:39:30 PMJun 7
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Abhishek Ghosh
Thank you Oliver. Based on that conversation, it seems doing this is not directly possible today. I've opened a feature request - https://issuetracker.google.com/u/0/issues/345611806 

- Abhishek
Reply all
Reply to author
Forward
0 new messages