Hi John,
The isolation by default of content scripts and JS added by the page is an important security boundary - while there are cases like this where mixing the two makes a lot of sense, it would also be dangerous if, for example, the page could overwrite something like `window.alert` to run malicious code that the extension doesn't expect when the extension calls it.
For this reason, you have to explicitly ask to run code in the main world - which you can absolutely do! For example, using the chrome.scripting API in MV3:
chrome.scripting.executeScript({
target: { tabId:
sender.tab.id },
world: 'MAIN',
files: ['example.js'],
});
This will run example.js in the "main world" where it will have access to `window.ethereum` and anything else defined by the page. Just be careful with this, as it means any data exposed to that script is also exposed to the page.
Hope that helps - let me know if you have any other questions.