Debugging Content Scripts from the console?

4,984 views
Skip to first unread message

Adam

unread,
Feb 17, 2011, 9:33:28 AM2/17/11
to Chromium-extensions
Is this possible? I have found no way to actually interact with a
content Script, other than reloading the extension and either passing
messages to it from background.html or bubbling events to it from the
page.

Is there anyway to interact with the variables and functions in a
content script from the console?

PhistucK

unread,
Feb 17, 2011, 9:46:38 AM2/17/11
to Adam, Chromium-extensions
Not really, as far as I try...
You can add a "debugger;" to your code, which will become a breakpoint that will be triggered (if reached) and use the Scripts panel to debug.
It may give you more information and let you debug within the world of the content script, I am not sure.

Example -

var a = "";
a++;
debugger; // This will create a breakpoint.
function bla()
{
 return;
}
a = bla();

PhistucK




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Adam

unread,
Feb 17, 2011, 9:52:23 AM2/17/11
to Chromium-extensions
Thanks PhistucK,

Adding "debugger;" totally worked. The console launches and you have
access to the isolated world the content script runs in. Once all
"debugger" breakpoints are passed over, the console returns
automatically to the webpage's world, and the content scripts world is
no longer accessible.

Either way, that vastly simplifies the content script debugging.

Thanks!

-Adam

On Feb 17, 9:46 am, PhistucK <phist...@gmail.com> wrote:
> Not really, as far as I try...
> You can add a "debugger;" to your code, which will become a breakpoint that
> will be triggered (if reached) and use the Scripts panel to debug.
> It may give you more information and let you debug within the world of the
> content script, I am not sure.
>
> Example -
>
> var a = "";
> a++;
> debugger; // This will create a breakpoint.
> function bla()
> {
>  return;}
>
> a = bla();
>
> ☆*PhistucK*
>
>
>
>
>
>
>
> On Thu, Feb 17, 2011 at 16:33, Adam <ldsfutbolpla...@gmail.com> wrote:
> > Is this possible? I have found no way to actually interact with a
> > content Script, other than reloading the extension and either passing
> > messages to it from background.html or bubbling events to it from the
> > page.
>
> > Is there anyway to interact with the variables and functions in a
> > content script from the console?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org.

Michael Gundlach

unread,
Feb 18, 2011, 12:15:41 PM2/18/11
to Adam, Chromium-extensions
You can also click a line of a script in the Scripts tab of the Developer Console to add a breakpoint -- then reload the page and execution should stop there.  No code modification necessary.

To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages