This is how I inject a click listener into pages
// background.js
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.url && !tab.url.startsWith('chrome://')) {
console.log("Injected");
console.log(tab.url);
chrome.scripting.executeScript({
target: { tabId: tabId, allFrames : true },
function: injectClickListener,
});
}
});
function injectClickListener() {
document.addEventListener('mouseup', (e) => {
const position = {
x: Math.round(e.clientX) * window.devicePixelRatio,
y: Math.round(e.clientY) * window.devicePixelRatio
};
doSomething();
}, true);
}
This is my manifest
{
"manifest_version": 3,
"name": "Test extension",
"version": "1.0",
"description": "Test",
"permissions": ["activeTab", "scripting", "tabs"],
"host_permissions": [
"<all_urls>"
],
"background": {
"service_worker": "background.js"
}
}
This doesn’t work on pdf files opened on Chrome using the default Chrome pdf viewer. I can see from the logs that the script gets injected fine, but the clicks don’t get detected. The problem applies to both local and remote pdf files. Even if the Chrome pdf viewer loads up the contents in frames or other nested objects, I was expecting clicks to get detected because I’ve set allFrames : true
.
How do I fix this issue?