Search code examples
javascriptgoogle-chromelogginggoogle-chrome-extension

How to view logs of oauth.js in Google example code


I am trying to follow the code in this Chrome Developers documentation and some things were going wrong so I thought I would add some console.log messages from my oauth.js.

I can see the log message from my foreground javascript directly in chrome by right-clicking on any page and selecting "inspect"... and I can view the logs of my background javascript by selecting "service worker" from the manage extensions page... but viewing logs from oauth.js ? - I have no idea how or where to view them.

I know some console.log() calls must have been made just by inspecting the error report below:

enter image description here


Solution

  • Given that such a long time has passed without any answers I have thrashed around and come up with the following thoughts about viewing logs in chrome extensions.

    There appear to be three different scenarios for executing JavaScript in a chrome extension and viewing the logs of each of them is achieved very differently...

    1. We have the "content script". To view the logs of these just right click on the main body of your browser and select "developer tools" then "inspect" and navigate to the "console" display.

    2. We have the "service worker" which is JavaScript that runs all the time. To view those logs we need to go to the "manage extensions" page then click the extension's "Inspect views service worker" link (only visible when developer mode is selected)

    3. We have any JavaScript that is called from the "default_popup". To view this you must first make the popup appear by clicking on the extensions's icon in the top toolbar of chrome. Then right click within the popup display itself and select "developer tools" then "inspect".

    One extra quirk people should know is that the service worker will never be shut down while logs are being viewed. So if you are viewing the service worker's logs and you want to reload a new version of the extension then you must close the viewing window first.