After recently updating Chrome to version 55.0.2883.75, I encountered an issue with my self-developed Chrome Plugin used for parsing HTML files. In the plugin, I utilize chrome.tabs.executescript to retrieve data from a background HTML page. Previously, I successfully saved the parsed data from the background page into a global variable using chrome.extension.onRequest and accessed it in the callback function of chrome.tabs.executescript for processing.
However, upon upgrading to Version 55.0.2883.75, this functionality stopped working. How can I now access the global variables in the new version?
Below is a snippet of my code:
Step 1 :
chrome.extension.onRequest.addListener(
function (request, sender, sendResponse) {
parser = new DOMParser();
htmlDoc = parser.parseFromString(request.content, "text/html");
// The outputJson global variable is populated here
outputJson = parseMyPage(outputJson, htmlDoc);
});
Step 2:
chrome.tabs.getSelected(null, function (tab) {
// Inject script onto the page
chrome.tabs.executeScript(tab.id,{
code: "chrome.extension.sendRequest({content: document.body.innerHTML}, function(response) { console.log('success'); });"
}, function () {
// Code to access global variables
if (outputJson && null != outputJson) {
// Perform other actions based on the global variable
}
});
});