Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9053389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:24:37+00:00 2026-06-16T13:24:37+00:00

I’m trying to migrate my Chrome extension to manifest 2. The current version uses

  • 0

I’m trying to migrate my Chrome extension to manifest 2. The current version uses a background.html page that is basically one big script tag. Since that is no longer possible, I switched to using a background.js script and after much search and experiments, still failing to inject a script from an external file. In the current version I just use document.write to inject a script tag that will run when the browser loads and I haven’t found a way to do this now.

I’m aware of the chrome.tabs.onUpdated.addListener function and the ability to inject script per tab update using a XMLHttpRequest object, but the script I want to run should do so only when the browser loads.

current code (in a script tag in a background.html file):

document.write("<script type='text/javascript' src='" + url + "'></script>");

In the background.js file this now leads to an error:
Refused to load the script ‘http://www.mydomain.com/script.js&#8217; because it violates the following Content Security Policy directive: “script-src ‘self’ chrome-extension-resource:”.

I’ve tried all sorts of code, including:

var s = document.createElement('script');
s.src = chrome.extension.getURL(url);
s.onload = function() {
    this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);

But seems like this will work only for local script files whereas I need to load an external online file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:24:38+00:00Added an answer on June 16, 2026 at 1:24 pm

    The error you are getting is due the directive content_security_policy in the manifest. You need to specify the domain of your script as part of it. Here’s an example for jQuery:

    "content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'"
    

    And in the Background.html page

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    

    This didn’t cause me any error. About to when download this script, that’s up to your extension architecture, but there’s many ways you can tell your application how to do it. Remember that the first thing your application loads is your Background page, so you can do send a message from your Background page to your content script when it’s loaded. Example:

    /**
    * Listener for Displaying the Extension Page Action when the Tab is updated.
    * @private
    * @event displayPageAction
    * @param {Number} tabId The tabId given by the tabs listener to know which tab was updated.
    * @param {Object} changeInfo The current status of the tab.
    * @param {Object} tab The metadata of the tab.
    **/
    var displayPageAction = function (tabId, changeInfo, tab) {
        var match = regexAIESEC.exec(tab.url); // var regexAIESEC = new RegExp(/http:\/\/www.myaiesec.net\//);
        // We only display the Page Action if we are inside a MyAIESEC Tab.
        if(match && changeInfo.status == 'complete') {
            //We send the proper information to the content script to render our app.
             chrome.tabs.sendMessage(tab.id, {load: true}, function(response) {
                if(response) {
                    //After successfully getting the response, we show the Page Action Icon.
                    chrome.pageAction.show(tab.id);     
                }
            });
        }
    };
    

    This is an example of when to show a Page action after the tabs was updated. In a previous code:

    chrome.tabs.onUpdated.addListener(displayPageAction);
    

    You can read more about Content Security Policy for Chrome Extensions here and more about Message Passing here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.