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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:36:03+00:00 2026-05-26T17:36:03+00:00

I realized we can work at shared DOM ( according to manual ) from

  • 0

I realized we can work at shared DOM (according to manual) from content scripts.

We can connect injected DOM content with our Content Scripts via

element.addEventListener('click',function(){ ourController.fnCallback(); });
// or
element.onclick = ourController.fnCallback;

But when injected DOM implements something like this:

<a href="javascript:ourController.fnCallback();">Click Me!</a>

thrown error is cannot call fnCallback() on undefined ourController (not exactly rewritten error messages)

Is there aby way we can communicate with our javascript object from injected dom like i tried in second example?

Object is defined in content_script.js like this:

var ourController = {
    fnCallback: function(){
        // code here
    }
};

and this code is placed directly in script loaded according to manifest like this:

"content_scripts": [ {
  "js": [ "content_script.js" ],
  "matches": [ "http://*/*", "https://*/*", "ftp://*/*" ],
  "run_at": "document_start"
}],
  • 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-26T17:36:04+00:00Added an answer on May 26, 2026 at 5:36 pm

    Solution to this problem comes out from documentation:

    Execution environment

    Content scripts execute in a special environment called an isolated world. They have access to the DOM of the page they are injected into, but not to any JavaScript variables or functions created by the page. It looks to each content script as if there is no other JavaScript executing on the page it is running on. The same is true in reverse: JavaScript running on the page cannot call any functions or access any variables defined by content scripts.

    So any injected content is not able to work with content script. Only solution is to use code like this from withing content scripts

    document.getElementById("elmID").addEventListener('click',function(){
            var data = //get the data from DOM or window state, not from content script
            chrome.extension.sendRequest({
                'request_data': data
            });
        })
    

    It will add click-event function which can communicate with content_script

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

Sidebar

Related Questions

Just downloaded the Visual Studio 2010 Premium and realized that can't compile the project,
To run a command on a single file, I recently realized I can do
I realized that I can have problems with single quotes in php arrays: <?php
This is what I had before (but realized that you can't obviously do it
I realized that you cannot just insert <iframe src=remote-page-here></iframe> and expect it to work,
I'm moving from an old shared host to a dedicated server at MediaTemple. The
Update Boilerpipe appears to work really well, but I realized that I don't need
I've just launched a site for a client at work and just realized there's
I have realized that I have to make Image from EBS Volume everytime when
I realize you can script Microsoft Office apps, but I'm looking for something more

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.