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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:13:00+00:00 2026-06-04T06:13:00+00:00

I want to make a Chrome extension that does this (automatically logs onto a

  • 0

I want to make a Chrome extension that does this (automatically logs onto a website, probably not the best approach since it was my first time doing JS) and has an option page where the user can set up his info and get it saved (localstorage?) so that the content script can access it as well as the options page.

Here’s what I’ve come to after a whole lot of researching, looking at examples etc.:
http://pastebin.com/yTiXp4VY (source code of all files there).

In the end I gave up and just used trial and error so there’s tons of errors there. The console is reporting it can’t run for security reasons. Please explain me what is wrong with this version. I don’t need you to fix my code, I am just learning JS.

  • 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-04T06:13:01+00:00Added an answer on June 4, 2026 at 6:13 am

    For most part you code seems to be correct. Only one note: your options page can access localStorage directly, it doesn’t need the background page for that. But the main issue seems to be the way your content script is built – it assumes that the user/password data will be available immediately (synchronously). That’s not how it works: you are sending a message to the background page, eventually the background page will answer and your callback in the content script will be called. The simplest approach is to delay all actions until that happens and you have the data. And it should be easier to send a single message to the background page that will give you all the data. Something like this:

    var userName = null;
    var passWord = null;
    
    chrome.extension.sendRequest( { eventName: "getLogin" },
        function(response) {
            userName = response.user;
            passWord = response.pass;
    
            // Now we can continue doing whatever we are doing
            checkIfAutoUrl();
        }
    );
    

    And the message processing in your background page would look like this:

    function onRequest(request, sender, sendResponse) {
        if (request.eventName == "getLogin") {
            sendResponse({user: getStorage("user"), pass: getStorage("pass")});
        }
    }
    

    Note that the response is an object with two properties user and pass here – this way the content script can immediately continue once it got the response, it has all the necessary data and doesn’t need to wait for a second response.

    Update: Concerning the error message you get: the Content Security Policy is meant to protect your extension from being exploited by a malicious website. One part of that protection is disallowing inline scripts in HTML – like onload="load_options()". All scripts that will run need to be placed in your JavaScript files. So instead of this onload attribute you can put the following into options.js:

    window.addEventListener("load", load_options, false);
    

    See addEventListener documentation on MDN.

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

Sidebar

Related Questions

I'm really confused. I want to make a Chrome Extension that can update a
I want to make a chrome extension that will connect to a localhost server
I want to implement an extension in Chrome that I'd display some text related
I am working in chrome extension, I want to make paging for table which
I'm trying to make a chrome extension on my toolbar that, when clicked, will
i want to make a chrome extension on google reader and i found a
I've been experimenting with a Chrome Extension, and I want to make one similar
I am trying to make a Chrome extension for personal use that makes all
I want to make a chrome extension which performs a certain action when the
This is not just for Google Chrome extension but also for JavaScript I am

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.