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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:58:45+00:00 2026-06-02T01:58:45+00:00

Im making a really simple Chrome extension, what redirects pages what are on http

  • 0

Im making a really simple Chrome extension, what redirects pages what are on http protocol ,to https protocol, if exist. Im on debugging, and i found facebook, what has both http, and https.

The code is here:

function redirect() {    
    chrome.tabs.query({active: true}, function(tabArray) {  
        var currentURL = tabArray[0].url;               //http://facebook.com
        var httpsURL = generateSSL(currentURL);         //https://facebook.com
        if(httpsURL == currentURL){
            console.log(currentURL+" is already on HTTPS");
            chrome.browserAction.setIcon({path:"../images/padlock_green.png"});
        } else if(checkSSL(httpsURL)){                      
            chrome.tabs.update(tabArray[0].id, {url: httpsURL});
            chrome.browserAction.setIcon({path:"../images/padlock_green.png"});
            chrome.browserAction.setBadgeText({text:"SSL"});
            console.log("SSL found,"+currentURL+" redirected to"+httpsURL);
        } else {
            //donothing
            console.log(currentURL+" has no SSL");
            chrome.browserAction.setIcon({path:"../images/padlock_red.png"});
        }
    });
}

ajax call:

function checkSSL(url){
    $.support.ajax = true;
    $.ajax({
        url: url,
        type:'HEAD',
        error: function()
        {
            return false;
        },
        success: function()
        {
            return true;
        }
    });
}

The problem is, that i get in console the following error msg:

XMLHttpRequest cannot load https://www.facebook.com/. Origin chrome-extension://pgidanbjmliilmmohlphbagcapafjjpg is not allowed by Access-Control-Allow-Origin.

I dont have any ideas what could be the problem 🙁

  • 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-02T01:58:47+00:00Added an answer on June 2, 2026 at 1:58 am

    Your code has a couple of small issues:

    • Your manifest file only requests permissions for http://*/*, not https://*/*, so your request to an HTTPS site is failing. You need the permission to be *://*/*, so you can get all pages on all domains over all protocols, not just over HTTP.

    • A second issue is that you expect your $.ajax call to return a boolean, but that is not what happens. The $.ajax call has two callbacks that each return a boolean, but checkSSL terminates before the Ajax call completes, meaning that checkSSL always returns undefined.

    What you want to do instead is provide checkSSL with a callback function as an argument:

    function checkSSL(url, callback){
        $.ajax({
            url: url,
            type:'HEAD',
            error: function() { callback(false); },
            success: function() { callback(true); }
        });
    }
    

    Then, use that callback to run call the code after the call to checkSSL:

    function redirect() {    
        chrome.tabs.query({active: true}, function(tabArray) {  
            var currentURL = tabArray[0].url;               //http://facebook.com
            var httpsURL = generateSSL(currentURL);         //https://facebook.com
            if(httpsURL == currentURL){
                console.log(currentURL+" is already on HTTPS");
                chrome.browserAction.setIcon({path:"../images/padlock_green.png"});
            } else {
                // call checkSSL and take action in an anonymous callback function!
                checkSSL(httpsURL, function(urlDoesExist) { 
                    if(urlDoesExist) {                 
                        chrome.tabs.update(tabArray[0].id, {url: httpsURL});
                        chrome.browserAction.setIcon({path:"../images/padlock_green.png"});
                        chrome.browserAction.setBadgeText({text:"SSL"});
                        console.log("SSL found,"+currentURL+" redirected to"+httpsURL);
                    } else {
                        //donothing
                        console.log(currentURL+" has no SSL");
                        chrome.browserAction.setIcon({path:"../images/padlock_red.png"});
                    }
                });
            }
        });
    }
    

    Notice the changes to the code below the first else. We can’t decide what to do until the Ajax call has resolved, so we have the Ajax success and error functions fire a callback with a boolean argument. That callback function then takes action based on the value of the boolean.

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

Sidebar

Related Questions

I'm making a really simple virtual host administrator in my office intranet (on a
I'm making a really simple email validation script that basically just checks the following
Simple question really. As part of some data structure changes that I've been making,
I'm probably making a really simple error somewhere, but for some reason the event
I'm a newbie making a really simple app in rails, but I have no
I've got this simple problem that is really making me crazy. I've got a
I've stubmled upon a strange Google Chrome problem. I'm making a simple script for
so I'm making a really simple program in which I want one sprite to
Just making a really simple Tcl/Tk program to learn, but I'm having a little
I know it might be a duplicate question but it is really making me

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.