AngularJS Chrome Extension has been flagged as potentially harmful, despite the implementation of compileProvider.aHrefSanitizationWhitelist. This has resulted

I have previously shared this issue, however, the suggested solutions did not resolve it. Therefore, I am reposting with a more widely recognized solution:

I am currently working on developing a chrome extension using AngularJS. In my base directive, I am attempting to display an image (from a local file). Here is my manifest:

{
    "name": "The Extension",
    "manifest_version": 2,
    "description": "An extension for Chrome browsers",
    "version": "1.0.0",
    "background": {
        "persistent": false,
        "scripts": [ "background.js" ]
    },
    "permissions": ["tabs", "<all_urls>"],
    "web_accessible_resources": ["assets/img/extension-logo.png"]
}

Within my app.js (loaded from background.js):

// Adding the base directive in the app
var app = '<div class="my-extension"><div base></div></div>';
var wrapper = '<div ng-non-bindable>' + app + '</div>';
$('body').append(wrapper);
var myExtension = angular.module('my-extension', ['baseModule']);

myExtension.config(['$compileProvider', function ($compileProvider) {
    $compileProvider.aHrefSanitizationWhitelist(/^\s(https?ftp|mailto|local|data|chrome-extension):/);
}]);

window.name = '';
angular.bootstrap($('.my-extension')[0], ['my-extension']);

The 'base' directive code snippet:

var baseModule = angular.module('baseModule', []);
baseModule.directive('base', ['$http', function($http) {
    return {
        replace: true,
        template: '<div>Hello World <img src={{logoImgURL}} /></div>',
        link: function(scope, elem, attrs) {
            scope.logoImgURL = chrome.extension.getURL("assets/img/extension-logo.png");
        }
    }
}]);

The source of the image is bound to the following value:

src='unsafe:chrome-extension://lmkgimpeoaoblkhioebjoefpkhckcojf/assets/img/extension-logo.png/'

I apologize if this question seems trivial, as I am very new to extension development.

Answer №1

It is recommended to include chrome-extension in the list of allowed sources for image URLs, similar to what you have done for anchor links (a href).

myExtension.config(['$compileProvider', function ($compileProvider) {
    // ...
    $compileProvider.imgSrcSanitizationWhitelist(/^\s*((https?|ftp|file|blob|chrome-extension):|data:image\/)/);
}]);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Cookies in an AJAX Request for Cross-Domain Communication with Pure Javascript

I am in the process of developing an Analytics application and I'm seeking a method to uniquely identify each user's device. Currently, my approach involves generating a "cookie" from the server side to track all page clicks and interactions thro ...

retrieving the value of an object key based on changing information

console.log(x, obj.fares) //return undefined output adultFare Object {adultFare: "9.00", childFare: null, seniorCitizenFare: null, disabledFare: null,} How do I retrieve the adultFare value from the object? Is looping through the keys necessary? I expec ...

Activate simultaneous HTML5 videos on iOS devices with a simple click

I am currently in the process of developing a webpage that will play various videos when specific elements are clicked. Although the functionality works perfectly on desktop computers, it encounters an issue on iOS devices. The problem arises when the elem ...

Converting Firebase TIMESTAMP values to human-readable date and time

Utilizing Firebase in my chat application, I am adding a timestamp to the chat object using the Firebase.ServerValue.TIMESTAMP method. I want to display the time when the message was received in the chat application using this timestamp. If it is the cur ...

Having trouble with my jQuery .hover() code not running as expected

Whenever I hover over my divs, I want them to change color. However, the code doesn't seem to be working as expected when I try to do so. I suspect that the issue might be related to the z-index property used in the class that I am trying to hover ove ...

BookshelfJS: Establishing a One-to-One Relationship

Within my database, I am working with two tables - User and Address. The User table consists of the following two methods: shippingAddress: function() { var Address = require(appRoot + '/config/db').model('Address'); return thi ...

Observing the closing of a modal window from a different controller in AngularJS

Within my main controller, I have a function called $scope.showDialog: $scope.showDialog = function(ev) { $mdDialog.show({ controller: 'DialogController', templateUrl: 'partials/dialog.tmpl.ejs', targetEvent: ev ...

React component is unable to identify prop

I'm attempting to send an array of objects from the main App.js file to a smaller component using props. However, for some reason, the prop is not being recognized within the smaller component file. https://i.stack.imgur.com/WuyFr.png https://i.stac ...

What is the correct method for calculating the sum of one input field and multiple output fields?

I have a single input field and multiple calculated output fields using JavaScript :Click here to view the screenshot of the calculated problem You can see the live preview on this link: . When you visit this link, enter "Base on your annual bill amount: ...

The unexpected occurence of the Onbeforeunload exception

I am attempting to create an exception for onbeforeunload and display a warning about potential data loss whenever the quantity is not zero: Here is what I have tried so far: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

Converting HTML to a Text String (not for display) using Angular

When it comes to displaying HTML in Angular, there are numerous approaches available. For example, using $sce.trustAsHtml(myHtmlVariable) is one way to achieve this. However, I am interested in creating something like the following: myStringVariable = s ...

Error: The application encountered an issue while trying to initialize the module

Forgive me for asking, but I have searched many topics with the same name and they didn't help. It seems like everyone has their own specific code. var app = angular.module('iop', []); // Setting up the service factory to create our ...

Malfunctioning Bootstrap collapse feature

I am experiencing an issue with my modal that contains 2 blocks. When I click on the .emailInbound checkbox, it opens the .in-serv-container, but when I click on the .accordion-heading to reveal the comment section, the .in-serv-container collapses. What c ...

Issue: No default template engine specified and no file extension provided. (Using Express framework)

While I came across numerous questions with a similar title, they only provided me with partial help and did not completely resolve the error that plagued me. Just to provide some context, I had created a file named listing.js as a tool for running node c ...

ngIf not recognizing dynamically assigned variables

I'm having a code snippet that looks like this ng-show="!edit{{id}} && imageUrl" However, it doesn't seem to be working. On the other hand, ng-show="!edit1 && imageUrl" works perfectly fine. Could there be an issue with the s ...

Arranging the Bars in a Bar Chart Using Chart.JS

Lately, I've been playing around with ChartJS and encountering an issue with sorting the bars in descending order, from lowest to highest. Despite my efforts to troubleshoot, I haven't had any success in resolving it. ...

Alter Express routes automatically upon updating the CMS

Currently, I am working on a project that utilizes NextJS with Express for server-side routing. lib/routes/getPages const routes = require('next-routes')(); const getEntries = require('../helpers/getEntries'); module.exports = async ...

Testing a service with $resource using unit tests

Struggling to write a unit test for an existing service and puzzled by the unexpected data appearing in the results, leading to test failures. Let's take a look at the key components: Service Method: function createAddressType(newAddressType) { var ...

Mastering the Art of jQuery: Easily Choosing and Concealing a Div Element

I'm currently facing challenges in removing a div upon successful AJAX completion. The issue I'm encountering is that the word "Added" appears twice after success, indicating that I am not properly selecting the two divs containing it. Any sugges ...

Can I use a single component for all routes in NextJS?

Just starting out with NextJS and facing a simple problem: I'm wondering if it's possible to achieve the following setup using NextJS // with react-router-dom <Router> <> <Header /> <Switch> & ...