5

If I open up the JavaScript console in Chrome Developer Tools to debug my extension's content scripts, I don't get the context of the content scripts. For example, jQuery isn't accessible, and I can't get access to my global variables unless I go to the debugger and set up a breakpoint.

Am I just missing something? It would be great to be able to check my global variables from the JS console or invoke jQuery.

huyz
  • 2,297
  • 3
  • 25
  • 34

2 Answers2

2

It is not possible at the moment to perform evaluations in context of a content script except the described way of setting a breakpoint/inserting debugger statement and pausing inside the script. I filed a bug on this, You can add yourself to the CC list to track its progress.

Sudarshan
  • 18,140
  • 7
  • 53
  • 61
Yury Semikhatsky
  • 2,144
  • 13
  • 12
  • 4
    Update: We added context selector to the DevTools console a while ago so it should be possible now to perform evaluations in the context of a content script. – Yury Semikhatsky Feb 28 '13 at 08:55
1

You can achieve this indirectly by triggering the debugger in the isolated world of the content script:

  1. Select the tab whose content scripts you wish to inspect
  2. Open the dev tools for that tab
  3. Open the inspector for your extension's background page (or any other extension page) in a popup window
  4. Run chrome.tabs.executeScript(undefined, {'code': 'debugger'})

You should also be able to use the debugger keyword directly in your content script, if there's a place in the execution that you wish to inspect.

Mihai Parparita
  • 4,236
  • 1
  • 23
  • 30