Chrome debuuger api for google docs and youtube

199 views
Skip to first unread message

lovish jain

unread,
Sep 9, 2021, 10:36:16 AM9/9/21
to Chromium Extensions
 Hi,
I am developing extension having manifest version "2.0".
Recently I need to use chrome.debugger.attach api on my google presentation(basically google docs) and youtube.com, but whenever I try to attach debugger on google docs and youtube, it gives error in background console of "cannot attach to this target", basically debugger is not attaching to them, apart from this it is attaching and working good on all other domains. 
Note: Added debugger permission,
I used This part of code, here actually just for testing purpose I am printing browser version, but main aim is to get a mouse click.
-> here tab.id is the id of the active tab, "1.3" is stable debugger protocol version,

chrome.debugger.attach({ tabId: tab.id }, "1.3", function(){
    if(!runtime.LastError){
      chrome.debugger.sendCommand({ tabId: tab.id } , 'Browser.getVersion' , function(data){
          console.log(data);
      })
    }
  });
Can anyone please guide me through this.. it will be great help.

Thanks
Lovish

Simeon Vincent

unread,
Sep 9, 2021, 8:47:38 PM9/9/21
to Chromium Extensions, lovis...@algoworks.com
Do you actually need to use Chrome DevTools Protocol (CDP)? Given what you've shared of your use case, this seems like it might be way more invasive and complicated than necessary. Content scripts also have access to a page's DOM and can observe click events. They also do this without displaying a warning bar saying the page is being remotely debugged.

Simeon - @dotproto
Chrome Extensions DevRel

wOxxOm

unread,
Sep 10, 2021, 10:20:41 AM9/10/21
to Chromium Extensions, lovis...@algoworks.com
Assuming you want to send a trusted click event, chrome.debugger is indeed the only solution. It's weird though because usually non-banking sites don't check the isTrusted property of an event.

As for the problem, it sounds like a known bug in Chrome caused by the presence of the built-in hosted apps for Google Drive, Docs, Sheets. These apps are completely useless on all desktop platforms, their only purpose IIRC is to provide a click button in the ChromeOS launcher. The solution/workaround is to open chrome://apps page and remove everything you didn't install yourself except for the non-removable Chrome Web Store app, specifically YouTube, Google Drive, Docs, Sheets.

Another problem may be yet another bug if you try to attach to a freshly created tab (chrome.tabs.create or chrome.windows.create). It can be solved by creating an empty about:blank tab, attaching to it, then navigating to the real URL.

lovish jain

unread,
Sep 16, 2021, 6:58:03 AM9/16/21
to Chromium Extensions, wOxxOm, lovish jain
Hi,
Thanks for sharing the valuable points regarding chrome debugger apis, I recently checked with attaching the debugger to a freshly created tab and redirecting the required url, and it worked for Youtube, and we were able to do our task using debugger api, but in case of google docs, as soon as the google presentation page loads completely, the debugger detaches itself automatically, It would be great if we also are able to get to this point.. please guide me through this..

wOxxOm

unread,
Sep 16, 2021, 7:25:34 AM9/16/21
to Chromium Extensions, lovis...@algoworks.com, wOxxOm
My post above already explains what you need to do so I don't understand what else I can add.

lovish jain

unread,
Sep 16, 2021, 8:42:51 AM9/16/21
to wOxxOm, Chromium Extensions
Actually, when we need to attach debugger on google docs (presentation page), we are attaching it to an empty tab and then redirecting it to google presentation url,and after that once the loading completes, the debugger detaches automatically, but i want to do some operations with the help of debugger, like click events, etc once the presentation page loads, and if i try to again attach debugger, on google docs, it throws error: "can't attach to this target" the previous one of my first post

Thanks

wOxxOm

unread,
Sep 16, 2021, 8:46:44 AM9/16/21
to Chromium Extensions, lovis...@algoworks.com, Chromium Extensions, wOxxOm
I still don't see any reaction for the second paragraph of my first post...

lovish jain

unread,
Sep 16, 2021, 10:00:49 AM9/16/21
to Chromium Extensions, wOxxOm, lovish jain, Chromium Extensions
Hi,
I went to chrome://apps and I found only google - Sheets, docs, slides . So nothing else is installed other than default ones. 
I am trying to attach the debugger to two different sites that require trusted events; YouTube and Google Presentations.
In the case of attaching the debugger to YouTube, I tried your suggestion where I attached to a random page (attaching to about:blank failed for some reason) and then I navigated to YouTube. That worked great (thank you). 
In the case of google presentations, I did the same, then navigated to the specific google presentation that I am trying to attach to. The debugger just detaches itself once the presentation URL loads. 
Would you happen to have any other ideas or tricks as to how I can get around this ?

wOxxOm

unread,
Sep 16, 2021, 10:11:14 AM9/16/21
to Chromium Extensions, lovis...@algoworks.com, wOxxOm, Chromium Extensions
As my first post says "remove everything you didn't install yourself except for the non-removable Chrome Web Store app, specifically YouTube, Google Drive, Docs, Sheets."

It means you need to remove YouTube, Google Drive, Docs, Sheets from chrome://apps.

English is not my native language so I guess the way I phrased it made you think that you should not delete the apps listed after "specifically".

Reply all
Reply to author
Forward
Message has been deleted
0 new messages