Using Google Charts in Chrome extension

user3262515

I want to use a chart library in my extension. Google Charts library seems to be the most convenient one. But I can't use it in the script I inject into the page. My manifest.json looks like this:

...
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"content_scripts": [
  {
    "js": ["loader.js", ...],
    ...
  }
],
...

But I always get these errors:

jsapi_compiled_format_module.js:1 Uncaught ReferenceError: google is not defined
jsapi_compiled_default_module.js:1 Uncaught ReferenceError: google is not defined
jsapi_compiled_ui_module.js:1 Uncaught ReferenceError: google is not defined
jsapi_compiled_corechart_module.js:1 Uncaught ReferenceError: google is not defined

And it is only one line in the script:

google.charts.load('current', {'packages':['corechart']});

So is it any way to make it work?

Xan

loader.js tries to add additional code by inserting <script> tags into the page.

Due to content script context isolation, those scripts execute in the page's context (and not the content script context). Therefore, google becomes defined in the page, but not in your script.

It's not clear if this can be worked around at all.

It's by far easier to find an alternative library that you can simply include with the extension, for example Chart.js.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Access Local Files using a Google Chrome Extension

From Dev

Redirect to url Using Google chrome Extension

From Dev

Defining a hotkey in Google documents using Chrome extension

From Dev

Authenticate Chrome extension with non-Google API using Google account

From Dev

angularjs and google chrome extension

From Dev

angularjs and google chrome extension

From Dev

Error with google chrome extension

From Dev

Google Chrome extension malware?

From Dev

Google Charts using JSON

From Dev

Injecting jQuery into Google.com using a Chrome Extension

From Dev

Changing the background of the google search page using my chrome extension

From Dev

Using google closure library inside chrome extension content script

From Dev

Is there a way to pass information from Google Chrome using an extension?

From Dev

Chrome Extension using DevTools

From Dev

Extension to Google Chrome browser that restarts Google Chrome

From Dev

Fire extension on very page Google Chrome Extension

From Dev

Google Chrome - Extension vs App

From Dev

Google Chrome Extension Opening Url

From Dev

Javascript not working in a google chrome extension

From Dev

Include google analytic in chrome extension

From Dev

Turn Google chrome extension "off" and "on"?

From Dev

How to uninstall this Google Chrome extension?

From Dev

Get JSON in a Google Chrome Extension

From Dev

Javascript not working in a google chrome extension

From Dev

Font not working in Google Chrome extension

From Dev

Show Google Chrome extension buttons

From Dev

Recognize if google chrome extension is installed

From Dev

Adding Google Charts or Similar to Chrome Packaged App

From Dev

Stopping navigation in Chrome (google chrome extension)

Related Related

HotTag

Archive