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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:43:03+00:00 2026-06-11T20:43:03+00:00

I would like to make a Chrome extension that provides a new object inside

  • 0

I would like to make a Chrome extension that provides a new object inside window. When a web page is viewed in a browser with the extension loaded, I would like window.mything to be available via Javascript. The window.mything object will have some functions that I will define in the extension, and these functions should be callable from console.log or any Javascript file when the page is viewed in a browser with the extension enabled.

I was able to successfully inject a Javascript file into the page by using a Content Script:

var s = document.createElement("script"); 
s.src = chrome.extension.getURL("mything.js");
document.getElementsByTagName("head")[0].appendChild(s);

mything.js looks like this:

window.mything = {thing: true};
console.log(window);

Whenever a page loads, I see the entire window object as I expect it to be in the console. However, I can’t interact with the window.mything object from the console. It seems at if the injected script hasn’t really modified the global window object.

How can I modify the global window object from a Chrome extension?

  • 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-11T20:43:05+00:00Added an answer on June 11, 2026 at 8:43 pm

    You can’t, not directly. From the content scripts documentation:

    However, content scripts have some limitations. They cannot:

    • Use chrome.* APIs (except for parts of chrome.extension)
    • Use variables or functions defined by their extension’s pages
    • Use variables or functions defined by web pages or by other content scripts

    (emphasis added)

    The window object the content script sees is not the same window object that the page sees.

    You can pass messages via the DOM, however, by using the window.postMessage method. Both your page and content script listen to the message event, and whenever you call window.postMessage from one of those places, the other will receive it. There’s an example of this on the “Content Scripts” documentation page.

    edit:
    You could potentially add some methods to the page by injecting a script from the content script. It still wouldn’t be able to communicate back with the rest of the extension though, without using something like postMessage, but you could at least add some things to the page’s window

    var elt = document.createElement("script");
    elt.innerHTML = "window.foo = {bar:function(){/*whatever*/}};"
    document.head.appendChild(elt);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to create a chrome extension to make requests for page resources that
I would like to create a google chrome extension. Specifically, I'd like to make
I'm creating an extension for Chrome (Just noraml HTML/JS). I would like to make
I would like to make a link from a web page to a file
I would like make an extension method for the generic class A which takes
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make a function that takes in a list of integers
I would like to have a button on a web page with the following
I am using chrome and am making an extension. I would like to know
I downloaded http://code.google.com/chrome/extensions/samples.html#ea2894c41cb8e80a4433a3e6c5772dadce9be90d . I would like make it it jQuery, but if i

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.