Refuse to load JS in Dart

600 views Asked by At

In my web page for Dart amount this script:

<script src="https://test.net/test/test.js"></script>  

but when you launch the application it gives me the following error:

Refused to load the script 'https://test.net/test/test.js' because it violates the following Content Security Policy directive: "default-src 'self' chrome-extension-resource:". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

I also set the Content Security Policy in manifest without any result:

"content_security_policy": "script-src 'self' https://test.net/test/"

Does anyone know how to fix?

Edit

This answer Loading external javascript in google chrome extension in Dart does not work.

Manifest:

..."permissions":["tabs","https://test.net/test/"],
"content_security_policy": "script-src 'self' https://test.net/test/; object-src 'self'",
"content_scripts": [
{
  "js": ["https://test.net/test/test.js"]
}
]...

Code:

JsObject spark=context['spark'];
print(spark);
spark.callMethod('login',["{username: '[email protected]', password: 'test'}"]);

Result:

null

Exception: The null object does not have a method 'callMethod'.

Dart does not support script injection dynamically:

Will there be a dynamic code injection for dart?

So how do you change the Content Security Policy?

Edit 2

Chrome reports this error when I install the app:

enter image description here

1

There are 1 answers

0
MalumaDev On BEST ANSWER

In a package app for Chrome you can not use the fields "content_scripts", "content_security_policy" and "tabs".

Dart also does not support script injection dynamically. As explained here:

Will there be a dynamic code injection for dart?

To use JS code must save it locally, import it into your html code:

<script src="test.js"></script>

and use the library dart:js to interact with the code js, like:

  test=context['test'];
  test.callMethod("login",["var1","var2",...,callback]);