William Werner
William Werner

Reputation: 71

Chrome.* API calls in the chrome dev console

I was wondering if it is possible to use chrome.* API calls in Chrome's dev console? When I try to type something like:

 chrome.system.cpu.getInfo(function(info){       
       console.log(JSON.stringify(info));   
 });

I get the error: "TypeError: Cannot read property 'cpu' of undefined"

Upvotes: 4

Views: 2350

Answers (1)

Xan
Xan

Reputation: 77541

Yes, it's possible - if you do it in a context of an existing extension and not in a page context.

First off, make sure that the extension in question has access to the API in question. For your example, the extension needs to have "system.cpu" permission.

Then, you need to do any of the following:

  1. Open the Dev Tools of the extension's background page, from chrome://extensions with Developer mode enabled.

  2. Open an extension's own page, i.e. an options page, a popup or something similar, if it has any. You can access a popup's Dev Tools by right-clicking it and selecting "Inspect popup".

  3. Open Dev Tools for a page that already contains a content script injected by the extension. Then, go to Console tab, and in the dropdown at the top select the extension's context instead of <top frame>. Please note: you'll get the same API access level as a content script, which is limited and does not contain chrome.system.

Upvotes: 4

Related Questions