I am working on a Chrome devtools extension that exposes a function (extensionEntryPoint
) to the inspected page. The problem is that extensionEntryPoint
is not available at the initial scripts in the inspected page loads and runs. I can use it from window.onload
, but that is too late.
Here's my code:
manifest.json
:
{
"name": "Extension",
"version": "1",
"manifest_version": 2,
"permissions": [
"activeTab"
],
"web_accessible_resources": ["api.js"],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content-script.js"],
"run_at": "document_start",
"all_frames": true
}
]
}
content-script.js
:
const script = document.createElement("script");
script.src = chrome.extension.getURL("api.js");
document.documentElement.appendChild(script);
api.js
:
function extensionEntryPoint(data) {
console.log("Thanks for calling, I'll debug your data now!")
}
Ideally, I would want for extensionEntryPoint
to be available to any script on the page as it's loading (e.g. before DOMContentLoaded
fires). Is this possible?