'Catching events DOMContentLoaded and onload using Chrome plugin for each frame

I need to write chrome plugin to intercept events DOMContentLoaded or onload to gather statistics about the elements in each frame.

I have tried:

document.addEventListener ('DOMContentLoaded', onContentLoaded, false);

But it only works for background.html. I also tried:

chrome.tabs.executeScript (tabId, {file: "ContentLoaded.js", allFrames: true}, null);

Where ContentLoaded.js create an event listener for each frame, but it did not help.

document.onload = contentLoaded;

For each frame does not work at all. How can I catch this events for each frame?



Solution 1:[1]

Thanks Rob W

As I understand you mean following:

var stmt = "document.addEventListener('DOMContentLoaded', function (data){alert('onContentLoaded');}, false); alert('TEST');";
chrome.tabs.executeScript(tab.id,{code: stmt, allFrames: true}, null);

But it dose't work. I see alert 'TEST', that simply notify me about script ran, but I don't see alert 'onContentLoaded'.

Dose I understand you comment correct?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user1326729