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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:11:45+00:00 2026-05-27T21:11:45+00:00

While creating a Google Chrome extension, I have code that must remain in a

  • 0

While creating a Google Chrome extension, I have code that must remain in a separate javascript file:

separate.js
-----------
var x = "some dynamic value";
var y = "another dynamic value";
return x;

I would like to get the value of x from this code into a code included in my background page:

background.html
-----------
<!DOCTYPE html>
<html>
  <head><script src="code.js"></script></head>
</html>

_

code.js
-----------
chrome.tabs.executeScript(null, {file:"separate.js"}, function() {});

How do I go about retrieving a variable set in separate.js (say, y)? Is there a way to use executeScript() to get the return value of a script?

  • 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-27T21:11:45+00:00Added an answer on May 27, 2026 at 9:11 pm

    At your code.js (injected by your extension), make use of chrome.extension.sendRequest:

    var y = "variable to send";
    function f_callback(response) {
        alert(response);
    }
    chrome.extension.sendRequest({y: y}, f_callback); //<-- Trigger
    

    At separate.js (at background.html), use chrome.extension.onRequest:

    function listener(o_request, o_sender, f_callback) {
        // This function is triggered by the function, see above
        alert(o_request.y); //<---y
        f_callback("Done something"); //<-- Calls callback. Can only be done once!
    }
    chrome.extension.onRequest.addListener(listener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While creating JavaScript with ASP.NET MVC I noticed several scope warnings and realized that
So I'm creating my first chrome extension and was extremely confused for a while
I have code which is creating a XML document for Google Shopping. Google is
While creating a file synchronization program in C# I tried to make a method
While creating classes in Java I often find myself creating instance-level collections that I
I just noticed while creating a RESTful WCF service that the Method parameter on
I'm passing some numeric arguments while creating a process (in VC++) I'm stuck at
in this answer he said that i can use RIA services while creating my
Im looking for some help creating a graph using the google chart API I
while creating a library that will be used on several projects, I encountered an

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.