简体   繁体   中英

Refuse to load JS in Dart

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: 'test@email.com', 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:

在此处输入图片说明

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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM