I am trying to use Angular with a list of apps, and each one is a link to see an app in more detail (apps/app.id
):
<a id="{{app.id}}" href="apps/{{app.id}}" >{{app.name}}</a>
Every time I click on one of these links, Chrome shows the URL as
unsafe:chrome-extension://kpbipnfncdpgejhmdneaagc.../apps/app.id
Where does the unsafe:
come from?
You need to explicitly add URL protocols to Angular's whitelist using a regular expression. Only
http
,https
,ftp
andmailto
are enabled by default. Angular will prefix a non-whitelisted URL withunsafe:
when using a protocol such aschrome-extension:
.A good place to whitelist the
chrome-extension:
protocol would be in your module's config block:The same procedure also applies when you need to use protocols such as
file:
andtel:
.Please see the AngularJS $compileProvider API documentation for more info.
For
Angular 2+
you can useDomSanitizer
'sbypassSecurityTrustResourceUrl
method.If you just need for mail, tel and sms use this:
Google Chrome require its extensions to cooperate with
Content Security Policy (CSP)
.You need to modify your extension to fulfill the requirements of
CSP
.https://developer.chrome.com/extensions/contentSecurityPolicy.html
https://developer.mozilla.org/en-US/docs/Security/CSP
Also, angularJS has
ngCsp
directive which you need to use.http://docs.angularjs.org/api/ng.directive:ngCsp
In case anyone has this problem with images, as well: