The extension page causes AngularJS to alter URLs to "unsafe:"

My goal is to integrate Angular with a list of apps, where each app is represented by a link that allows users to view more details (apps/app.id):

<a id="{{app.id}}" href="apps/{{app.id}}">{{app.name}}</a>

Whenever I click on any of these links, Chrome displays the URL as:

unsafe:chrome-extension://kpbipnfncdpgejhmdneaagc.../apps/app.id

I'm curious about where the unsafe: prefix in the URL originates from.

Answer №1

To ensure that Angular allows specific URL protocols, you must modify its whitelist using a regular expression. By default, only http, https, ftp, and mailto are approved. When utilizing a protocol like chrome-extension: that is not whitelisted, Angular will prepend the URL with unsafe:.

An effective approach to include the chrome-extension: protocol in the whitelist is within your module's configuration block:

var app = angular.module( 'myApp', [] )
.config( [
    '$compileProvider',
    function( $compileProvider )
    {   
        $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
        // For Angular versions before v1.2, use $compileProvider.urlSanitizationWhitelist(...)
    }
]);

This same method should be used when needing to utilize protocols like file: and tel:.

For further information, please refer to the AngularJS $compileProvider API documentation.

Answer №2

If you encounter issues with images, try this solution:

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

Answer №3

For those seeking to manage email, telephone and text communication efficiently:

app.config(['$compileProvider', function ($compileProvider) {
    $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|sms|tel):/);
}]);

Answer №4

<a href="{{applicant.resume}}" download> download resume</a>


var app = angular.module("myApp", []);

    app.config(['$compileProvider', function($compileProvider) {
         $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|local|data|chrome-extension):/);
        $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|local|data|chrome-extension):/);

        }]);

Answer №6

To implement safe URL handling in Angular 2+, you can leverage the bypassSecurityTrustResourceUrl method provided by DomSanitizer.

import {DomSanitizer} from '@angular/platform-browser';

class ExampleComponent {
    sanitizedURL : SafeResourceUrl;

    constructor(
        private sanitizer: DomSanitizer){
        this.sanitizedURL = this.sanitizer.bypassSecurityTrustResourceUrl(); 
    }
}

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

Angular Protractor testing: achieving precise column name matching

I am new to writing protractor tests and currently navigating my way through it. The angular code I am trying to test looks like this: <tr ng-repeat="identifier in contentIdentifiers"> <td>{{identifier.contentIdentifier}}</td> & ...

The JavaScript function's argument is determined by the value submitted in EJS

I am currently in the process of developing an express application. One of the key features involves a drop-down menu where the selected value is sent to users.js to trigger a MongoDB query. The results of this query are then returned to the EJS template a ...

"Implementing JavaScript Validation for Textboxes: A Step-by-Step Guide

I need some help with restricting the input of a textbox within a gridview to only 'X' or 'O'. I am not very familiar with javascript, so any guidance on how to accomplish this would be greatly appreciated. It's worth noting that t ...

Develop a gallery similar to YouTube or Vimeo

Is there a way to display a collection of SWF movies in a single DIV, with one SWF already set as the default? Something like a photo gallery but for SWFs. I would like to implement this using JQuery. Any suggestions or tips on how to achieve this? ...

Guide to setting up a datePicker in a cellEditorSelector

In my grid, I want to have different editors for different rows within the same column. The ag-Grid documentation provides information on how to achieve this using colDef.cellEditorSelector as a function: link I have successfully created unique editors fo ...

Is the alert still displayed during a frozen UI, even when it is within a synchronous ajax call?

Here is the code snippet for implementing global AJAX functionality. jQuery(function (){ $(document).ajaxStop(function() { alert("stop"); }); $(document).ajaxStart(function() { al ...

Error: JSON parsing failed due to an unexpected token "u" at the beginning of the JSON string. This occurred in an anonymous function when

Implementing reCaptcha in my firebase project has been successful. I am now sending form data and the captcha response using grecaptcha.getResponse() to my server upon clicking the send button. Below is the code snippet from client.js: $('.sendUrl ...

Ways to evaluate server side validation in AngularJS web applications

I am currently working on a project that involves Spring and AngularJS 1.x. When it comes to test automation, I am considering using Selenium as a functional testing tool. While client side form validation is straightforward to test with this tool, I am f ...

In the test environment, only a portion of the JavaScript code is executed, but it functions properly in both the production and development environments of

Rails 3 Currently facing an issue with a list inside a form: <%= form_for @article do |f| %> <ul> <% @product.each do |p| %> <li id="product_<%=p.id%>"> <div> <%= f.radio_button(:p_id, p ...

Dynamically passing Array data in URL to invoke a C# web API endpoint

Here is the JSON data I retrieved from the backend: {"langs":[{"cisAreaId":100,"area":"Prog","name":"C#"},{"cisAreaId":110,"area":"Prog","name":"Java"},{"cisAreaId":120,"area":"Prog","name":"MS.NET languages(VB.NET,etc)"},{"cisAreaId":130,"area":"Prog","n ...

Is it possible to prevent users from clearing data in an Android application when using Ionic framework?

Currently, I am developing an app using the Ionic framework. The data is being stored on the mobile device via SQLite, but there is a concern that users can easily clear this data by clicking on the "clear data" button in the application info settings. The ...

Declaring a Javascript variable within an if statement does not alter the value of the global variable

Currently, I am working on enhancing my HTML projects by using JavaScript to modify the video source. Below is the video element in question. <div> <video id="songVid" onmouseover="controlsVid()"> <source src=&qu ...

ng-repeat binding stops working when using Parse.Cloud.run()

Explaining the problem at hand: utilizing AngularJS version 1.3.15 incorporating the Parse.com library version 1.4.2 the onscreen output linked to my controller isn't updating when the underlying structure undergoes updates The HTML code is straigh ...

Issues arise when using jQuery to manipulate HTML content within an Asp.Net environment

Recently, I found myself in a puzzling situation with a div that has the attribute runat="server". <div id="results" runat="server" class="results"></div> Using jQuery, I added HTML content to this div. $('.results').html('Add ...

Assign a unique variable to each div simultaneously

I am looking to implement a countdown feature for each DIV with the class (.topitembox) by incorporating specific JSON variables. $('#countdown_items .topitembox').each(function () { itmID = $(this).attr('class').replace(/[^0-9]/g, ...

Issues with ng-click functionality not activating on <li> HTML elements

I've been attempting to add ng-click functionality to my list, but it's not working as expected. I've tried adding the ng-repeat directive and also without it on li elements. Here is the snippet of HTML code: <ul class="nav nav-tabs"&g ...

Error in Rails 4: Unable to call $(...).previous function - TypeError

I've been attempting to create a link labeled "remove" underneath a text field to use JavaScript to destroy and hide it, but I'm running into an issue where it doesn't work and I'm receiving this error in the console: TypeError: $(...). ...

Trimming content within an editable div in JavaScript: A guide

I am working on an editable div feature where users can input text for comments. My goal is to eliminate any unnecessary spaces before and after the text. For example, if a user types: "&nbsp;&nbsp;Hello&nbsp;world&nbsp;&nbsp;&nbsp ...

React: Oops! Looks like there's an issue - this.props.update is not defined as

Hello everyone, I'm diving into the world of programming for the first time and I might ask some silly questions along the way. Currently, I'm working on integrating a date picker into a search application built with React. The user should be ab ...

Enhancing ng-grid with pagination by incorporating diverse images

I am currently working with a grid that displays images as values in one of its columns using the code below. { field: 'TR', displayName: 'Trigger Redundancy', cellTemplate: '<div class="ngCellText" ng-class="col.co ...