ebi ebi - 1 year ago 130
Javascript Question

Angular changes urls to "unsafe:" in extension page

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?

Answer Source

You need to explicitly add URL protocols to Angular's whitelist using a regular expression. Only http, https, ftp and mailto are enabled by default. Angular will prefix a non-whitelisted URL with unsafe: when using a protocol such as chrome-extension:.

A good place to whitelist the chrome-extension: protocol would be in your module's config block:

var app = angular.module( 'myApp', [] )
.config( [
    function( $compileProvider )
        // Angular before v1.2 uses $compileProvider.urlSanitizationWhitelist(...)

The same procedure also applies when you need to use protocols such as file: and tel:.

Please see the AngularJS $compileProvider API documentation for more info.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download