问题
I'm pretty new on chrome extensions and so far, I could manage to get the current tab title and mouse positions, however, I've made some searches and couldn't find a way to get the element attributes, such as "e.target.innerText" when I click on them, right click and get a new option, anything from a mouse input, does anyone knows how to do so?
This is what my popup.js looks like
window.onclick = e => {
chrome.extension.getBackgroundPage().chrome.tabs.executeScript(null, {
code:'chrome.runtime.sendMessage(document.title)'
});;
}
chrome.runtime.onMessage.addListener(function (message) {
document.getElementById('pagetitle').innerHTML = message;
});
回答1:
In your content.js, write the following code-
$(window).click(function(event) {
console.log("Click event: ", event);
});
Content scripts are files that run in the context of web pages. By using the standard Document Object Model (DOM), they are able to read details of the web pages the browser visits, make changes to them and pass information to their parent extension.
回答2:
Try hitting Ctrl-Shift-C after opening the inspector window
回答3:
you should get the target DOM first, such as document.getElementById('targetId'), and then , the DOM attribute can be shown.
来源:https://stackoverflow.com/questions/52921227/how-may-i-get-the-element-attributes-text-id-class-and-so-on-of-the-curren