Using Google Charts

796 views
Skip to first unread message

Freek Boulogne

unread,
Feb 20, 2022, 3:00:11 PM2/20/22
to Chromium Extensions
Hi,

I would like to use Google Charts in my extension.

But if I include
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
in my html file I get the following message.

Refused to load the script 'https://www.gstatic.com/charts/loader.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

Is there a way to use Google Charts in a Chrome extension?

Best regards and thanks in advance,
Freek

wOxxOm

unread,
Feb 20, 2022, 6:52:34 PM2/20/22
to Chromium Extensions, adim...@gmail.com
Download this script into a file and load it like your normal extension scripts.

Freek Boulogne

unread,
Feb 21, 2022, 2:20:25 AM2/21/22
to Chromium Extensions, wOxxOm, Freek Boulogne
Hi wOxxOm,

Thank you for your answer.

I've tried that, but that does not work because it loads loads of scripts (it is called loader.js). With Chart.js this does work, but they are not as powerful and beautiful as the Google Charts.

Any other idea?

Best regards and thanks in advance,
Freek

Jackie Han

unread,
Feb 21, 2022, 9:24:05 AM2/21/22
to Freek Boulogne, Chromium Extensions, wOxxOm
Google doesn't allow you to use it offline.

In MV2, you can change "script-src" to use it.

In MV3, you can't use it directly. Some suggestions:
1. just don't use it, and use other chart libraries that support offline work.
2. you can set up a remote iframe to use it, then pass data to that iframe.


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/e7918d31-394e-4759-8085-558772178b63n%40chromium.org.

Cuyler Stuwe

unread,
Feb 21, 2022, 9:33:48 AM2/21/22
to Jackie Han, Chromium Extensions, Freek Boulogne, wOxxOm
It’s delicious irony that Google’s restrictions toward “malicious code” have now interfered with the use of several of its own libraries. In addition to this, people have complained about Google’s advertising libraries and Firebase.

Poor attention to fundamental detail on Google’s part — Kinda reminds me of how Google Tasks (ironically) doesn’t have a “search” feature.

wOxxOm

unread,
Feb 21, 2022, 9:35:58 AM2/21/22
to Chromium Extensions, salem...@gmail.com, Chromium Extensions, adim...@gmail.com, wOxxOm, Jackie Han
FWIW, when and if https://crbug.com/1220994 is fixed, MV3 extensions will be able to load remote code inside their sandbox pages.

Borys Korobeinikov

unread,
Nov 2, 2022, 6:47:52 PM11/2/22
to Chromium Extensions, wOxxOm, salem...@gmail.com, Chromium Extensions, adim...@gmail.com, Jackie Han
Did anything change since Feb for using google charts within MV3 extension? Maybe it is being considered to allow remote load google charts code?

wOxxOm

unread,
Nov 3, 2022, 3:51:57 AM11/3/22
to Chromium Extensions, bo...@streak.com, wOxxOm, salem...@gmail.com, Chromium Extensions, adim...@gmail.com, Jackie Han
It depends on whether the server responds with ` Access-Control-Allow-Origin:*` header. If it does, it's not cross-origin, and is allowed. Looks like another evidence that ManifestV3 is a contradicting mess.

Stefan Van Damme

unread,
Nov 3, 2022, 4:09:45 AM11/3/22
to Chromium Extensions, wOxxOm, bo...@streak.com, salem...@gmail.com, Chromium Extensions, adim...@gmail.com, Jackie Han
@bo..,

Note: You can always use another alternative, which is chart.js. I am using this file in my Manifest V3 Chrome extension and it loads the chart fine.

Thanks,
Stefan vd

Robbi

unread,
Nov 3, 2022, 5:02:36 AM11/3/22
to Chromium Extensions, stefa...@gmail.com, wOxxOm, bo...@streak.com, salem...@gmail.com, Chromium Extensions, adim...@gmail.com, Jackie Han
@bo..,
I have been using Chart.js for many years and I have a great time.
Initially I focused on Google Charts, but given the impossibility of using these charts in extensions without the aid of an iframe\sandbox, it soon made me desist from just trying.
If I can express a personal opinion, GC will provide perhaps more types of charts, but for the charts that "matter" (I mean the ones you use the most) it sucks compared to chart.js, so: "Go on with Chart.js with no regret"

Aleem Mawani

unread,
Nov 3, 2022, 4:50:36 PM11/3/22
to Chromium Extensions, Robbi, stefa...@gmail.com, wOxxOm, Borys Korobeinikov, salem...@gmail.com, Chromium Extensions, adim...@gmail.com, Jackie Han
Unfortunately we have a lot of code written for google charts that we don't want to migrate to a new charting library. iFrame solution kind of works but it breaks tooltips and sizing. Ideally we could use it directly...
Reply all
Reply to author
Forward
0 new messages