I am making an extension that automatically updates team information for a browser game. Basically, I want to grab a window object (window.gameInfo.party) to use as variables in the popup to update names, types, health, etc.
I want a message posted each time updateGameInfo() is complete. This is part of the game’s code.
Here’s what I have so far:
manifest.json
{
"manifest_version": 3,
"name": "Pokerogue Team Tracker",
"description": "Display team information for the Pokerogue browser game",
"version": "1.0.0",
"permissions": ["storage", "activeTab"],
"content_scripts": [
{
"matches": ["https://pokerogue.net/*"],
"js": ["content.js"]
}
],
"externally_connectable": [
{
"matches": ["https://pokerogue.net/*"]
}
],
"background": {
"service_worker": "background.js",
"type": "module"
},
"action": {
"default_icon": {
"16": "images/icons/icon-rogueball.png",
"32": "images/icons/icon-rogueball.png",
"48": "images/icons/icon-rogueball.png",
"128": "images/icons/icon-rogueball.png"
},
"default_title": "Pokerogue Team Tracker",
"default_popup": "index.html"
}
}
content.js
chrome.runtime.sendMessage(
window.gameInfo,
function (response) {
console.log(response);
}
);
background.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log("background.js got a message")
console.log(request);
console.log(sender);
sendResponse("bar");
}
);
When I use a string (ex. “foo”) in the chrome.runtime.sendMessage, it does work. I think part of the problem is that gameInfo is not loaded on page load, but rather when you select to “continue” the game. So I need to it update when new information is available.
From there, I’m new to coding so I’m not sure how to pass those window.gameInfo.party into values that the popup can use to dynamically change.
Thank you for any help! I’ve been stuck on this step for hours and could use the help!