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 7491473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:03:40+00:00 2026-05-29T16:03:40+00:00

I have a chrome extension which monitors the browser in a special way, sending

  • 0

I have a chrome extension which monitors the browser in a special way, sending some data to a web-server. In the current configuration this is the localhost. So the content script contains a code like this:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(data)...
xhr.open('GET', url, true);
xhr.send();

where url parameter is ‘http://localhost/ctrl?params’ (or http://127.0.0.1/ctrl?params – it doesn’t matter).

Manifest-file contains all necessary permissions for cross-site requests.

The extension works fine on most sites, but on one site I get the error:

XMLHttpRequest cannot load http://localhost/ctrl?params. Origin http://www.thissite.com is not allowed by Access-Control-Allow-Origin.

I’ve tried several permissions which are proposed here (*://*/*, http://*/*, and <all_urls>), but no one helped to solve the problem.

So, the question is what can be wrong with this specific site (apparently there may be another sites with similar misbehaviour, and I’d like to know the nature of this), and how to fix the error?

  • 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-05-29T16:03:41+00:00Added an answer on May 29, 2026 at 4:03 pm

    (tl;dr: see two possible workarounds at the end of the answer)

    This is the series of events that happens, which leads to the behavior that you see:

    1. http://www.wix.com/ begins to load
    2. It has a <script> tag that asynchronously loads the Facebook Connect script:
      (function() {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
      }());
      
    3. Once the HTML (but not resources, including the Facebook Connect script) of the wix.com page loads, the DOMContentLoaded event fires. Since your content script uses "run_at" : "document_end", it gets injected and run at this time.
    4. Your content script runs the following code (as best as I can tell, it wants to do the bulk of its work after the load event fires):
      window.onload = function() {
        // code that eventually does the cross-origin XMLHttpRequest
      };
      
    5. The Facebook Connect script loads, and it has its own load event handler, which it adds with this snippet:
      (function() {
        var oldonload=window.onload;
        window.onload=function(){
          // Run new onload code
          if(oldonload) {
            if(typeof oldonload=='string') {
              eval(oldonload);
            } else {
              oldonload();
            }
          }
        };
      })();
      

      (this is the first key part) Since your script set the onload property, oldonload is your script’s load handler.

    6. Eventually, all resources are loaded, and the load event handler fires.
    7. Facebook Connect’s load handler is run, which run its own code, and then invokes oldonload. (this is the second key part) Since the page is invoking your load handler, it’s not running it in your script’s isolated world, but in the page’s “main world”. Only the script’s isolated world has cross-origin XMLHttpRequest access, so the request fails.

    To see a simplified test case of this, see this page (which mimics http://www.wix.com), which loads this script (which mimics Facebook Connect). I’ve also put up simplified versions of the content script and extension manifest.

    The fact that your load handler ends up running in the “main world” is most likely a manifestation of Chrome bug 87520 (the bug has security implications, so you might not be able to see it).

    There are two ways to work around this:

    1. Instead of using "run_at" : "document_end" and a load event handler, you can use the default running time (document_idle, after the document loads) and just have your code run inline.
    2. Instead of adding your load event handler by setting the window.onload property, use window.addEventListener('load', func). That way your event handler will not be visible to the Facebook Connect, so it’ll get run in the content script’s isolated world.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Chrome extension which is injecting some code into a web page
I have a chrome extension which makes some changes on the site (editing comments).
I have a chrome extension which have a server-side javascript and I need this
At the moment I am developing a Google Chrome Extension in which I have
I'm working on a chrome extension, which use asynchronous functions, and I have a
I have a small chrome extension which I want to use to change text.
I have a chrome extension in which I have two text boxes, one for
I have a windows application which installs a Chrome extension via the windows registry.
I'm building a Chrome extension, which uses multiple APIs. Currently I have it set
I have an chrome extension in which I want to automatically fill in a

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.