I am developing a Chrome extension to work, and one of the things he needs to do is read (read only, not modify) the object that we send to the website after it makes an asynchronous request on our servers. Basically I need to read the window.<our object name> and get what is there.
Now I know that this is possible, because I did it in the Tampermonkey script that I wrote. I was able to console.log(window.<our object name>) and it went in.
Tampermonkey is a Chrome extension, so there is no reason why it can access something, and another extension cannot.
But when I try to access this object, both from content scripts and from the entered code, I get nothing. When I get only the window object, it only partially arises, as if the extension were blind for certain parts of it. But if I am in the console on the page and I call window , I return the full window object. Rabies.
So, if the content scripts do not work, and the nested scripts do not work, and there is no reason why the pop-up scripts will be good here, how to do it?
Thank you very much!
UPDATE: as requested, here is the manifest. json (I took the page_redder example and worked it out to make sure I didn't make any weird errors):
{ "name": "Page Redder", "description": "Make the current page red", "version": "2.0", "permissions": [ "activeTab" ], "background": { "scripts": ["background.js"], "persistent": false }, "browser_action": { "default_title": "get my object" }, "content_scripts": [ { "matches": ["<all_urls>"], "js": ["content.js"] } ], "manifest_version": 2 }
And here is the content.js:
var getWindow = window.setTimeout(function() { console.log("From content script: " + window.<OBJECT NAME>); }, 5000);
And here is background.js:
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Called when the user clicks on the browser action. chrome.browserAction.onClicked.addListener(function(tab) { // No tabs or host permissions needed! chrome.tabs.executeScript({ code: 'console.log("From injected script:" + window.<OBJECT NAME>);' }); });
On startup, I get:
From the contents of the script: undefined From the entered script: undefined
But if I make a window. from the console, I understand. I even added a timeout to make sure the content of the script was not trying to get what had not yet loaded. But I can get the object manually before running the script, and it still gives me undefined.