AngularJS - Google Chrome扩展程序中的动态链接已损坏

Ila*_*sda 1 javascript google-chrome google-chrome-extension angularjs

我有一个问题,我一直在研究样本chrome扩展中的链接.

看起来Chrome认为我的内联代码(AngularJS绑定)是不安全的,基本上meana所有动态链接都不起作用.

例如,下面的链接(在HTML模板中,IndexCtrl):

<a href="#/edit/{{ i.id }}"> Edit </a>
Run Code Online (Sandbox Code Playgroud)

渲染到下面,当在chrome开发人员工具中查看时,我得到:

<a href="unsafe:chrome-extension://abcd/index.html#/edit/1"> Edit </a>
Run Code Online (Sandbox Code Playgroud)

请注意,id of /edit/1已经通过角度正确绑定 - 所以很可能chrome有一些安全功能,我将启用/禁用,但如何?

有什么建议吗?仅供参考,控制台中没有错误.

Ila*_*sda 5

确保执行以下操作:

  1. 包括CSP声明:

    <html lang="en" ng-app="app" ng-csp="">

  2. 使用 ng-href

    <a ng-href="#/edit/{{ item.id }}">Link</a>

  3. chrome-extensions添加到Href Sanitization White列表中

    var app = angular.module("app", []);
    app.config( function ($compileProvider) {
       $compileProvider.aHrefSanitizationWhitelist (/^\s*(https?|ftp|mailto|file|tel|chrome-extension):/);
    });
    
    Run Code Online (Sandbox Code Playgroud)