I'm running 5.0.335.0 dev on OS X (I have Ubuntu available as well).
I'm just getting started with extensions and trying to trace what is
happening when I make a simple JS call from my popup to my background
page. In particular I'd like to see console.log("") entries for both
pages in the order they were executed.
I created a simple background page:
<script type="text/javascript" >
function logIt(msg) {
alert("in background");
console.log(msg);
}
</script>
and a popup
<script type="text/javascript">
console.log("starting popup.html");
chrome.extension.getBackgroundPage().logIt("test log entry");
console.log("end popup.html");
</script>
If I open the popup using either a click (browser action) or via the
chrome-extension:// URL, I see the alert from the background page. If
I view the console (via chrome-extension) for popup, I see the two log
entries for popup but not the one from the background page.
So, newbie question: I can temporarily work around this using alerts
but as you can imagine that's less than optimal. Is there a view of
the log across all pages?
Thanks
Patrick
--
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.
I found one issue which was a silly mistake on my part. I have a
simple form for data entry on the popup, and had a submit button
triggering a JS function on submit; the form itself had no action.
However, because it was a submit button, the form was submitted
anyway, causing the popup to be refreshed. Apparently this causes the
debugger to lose its current context and reset in some fashion; this
made it impossible to track operations that were triggered indirectly
by the button, especially asynchronous database operations (those are,
in fact, quite a pain to work with).
I'll try the "logging page" approach you suggest, and will post back
if I have something clean to share.
Thanks!
Patrick
> Create a logger.html file, and let your extension "open" that file during
> launch. Now, let your background page communicate to that file directly, and
> the rest of your extension will just send a log message to your background
> page, which will send a new message to that "logger.html" window.
Now that I'm back at the keyboard...
I have a page called log_page.html. I can, on the one hand, open this
using chrome.tabs.create(null, {url:"log_page.html"}), but then I am
not allowed to execute scripts on it--the error I get (in the console
log for background) is that I have not asked for permissions to access
it: "Error during tabs.executeScript: Cannot access contents of url
"chrome-extension://bckjomonlngglmbijgecbhigdbeccmam/log_page.html".
Extension manifest must request permission to access this host."
However, in the manifest file I'm not allowed to grant rights to the
chrome-extension namespace.
I tried starting with "about:blank", but as that has no namespace I
can't grant rights to it, either.
Of course, I can fire up a web server on my machine to serve
log_page.html, and grant rights to http://localhost/*, but that sounds
a little like overkill.
Any way you know by which I can work around this?
Thanks
Patrick
Thanks
Patrick
first line of page:
var bgPage = chrome.extension.getBackgroundPage();
function log(message) {
console.log(message);
bgPage.log(message);
}
this gives me logging on the current Page (popup/otions) & the global
logging page (background), very simple and easy.. i should probabaly
wrap it in an object... but it's just so simple.
On Mar 2, 1:37 pm, Mohamed Mansour <m0.interact...@gmail.com> wrote:
> Aha Erik, the simplest solution! My bad Patrik! I was thinking closure style
> FloatLogger, in case you want users to see logs or something specific to
> your application if enabled in options.
>
> -
> Mohamed Mansour
> m...@chromium.org
>
>
>
> On Mon, Mar 1, 2010 at 5:59 PM, Erik Kay <erik...@chromium.org> wrote:
> > Why not just use your background page as the hub for your logs? The
> > background page is designed to be this kind of central hub.
>
> > chrome.extension.getBackgroundPage().console.log("hi");
>
> > Erik
>
> > On Mon, Mar 1, 2010 at 12:13 PM, Patrick Wright <pdoubl...@gmail.com>wrote:
>
> >> Hi Mohamed
>
> >> > Create a logger.html file, and let your extension "open" that file
> >> during
> >> > launch. Now, let your background page communicate to that file directly,
> >> and
> >> > the rest of your extension will just send a log message to your
> >> background
> >> > page, which will send a new message to that "logger.html" window.
>
> >> Now that I'm back at the keyboard...
>
> >> I have a page called log_page.html. I can, on the one hand, open this
> >> using chrome.tabs.create(null, {url:"log_page.html"}), but then I am
> >> not allowed to execute scripts on it--the error I get (in the console
> >> log for background) is that I have not asked for permissions to access
> >> it: "Error during tabs.executeScript: Cannot access contents of url
> >> "chrome-extension://bckjomonlngglmbijgecbhigdbeccmam/log_page.html".
> >> Extension manifest must request permission to access this host."
>
> >> However, in the manifest file I'm not allowed to grant rights to the
> >> chrome-extension namespace.
>
> >> I tried starting with "about:blank", but as that has no namespace I
> >> can't grant rights to it, either.
>
> >> Of course, I can fire up a web server on my machine to serve
> >> log_page.html, and grant rights tohttp://localhost/*, but that sounds
> >> a little like overkill.
>
> >> Any way you know by which I can work around this?
>
> >> Thanks
> >> Patrick
>
> >> --
> >> 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<chromium-extensions%2Bunsubscr...@chromium.org>
On Mon, Mar 1, 2010 at 11:59 PM, Erik Kay <eri...@chromium.org> wrote:
> Why not just use your background page as the hub for your logs? The
> background page is designed to be this kind of central hub.
> chrome.extension.getBackgroundPage().console.log("hi");
Newbie error. As most of my code was in my popup, I was typically
- reloading extension
- opening the popup in a new tab using chrome-extension://...
- switching back to the extensions page
- clicking on popup.html
The problem with this was that a refresh/reload of my popup caused me
to lose my log entries on the debug/console window. I now know that I
can open the console for the background page and leave it open between
reloads.
Patrick