简体   繁体   中英

WebExtension: collect infos on all iframes of current page

I'm writing a WebExtension that identify fields using a given criterion in a web page.

The content script which is loaded with every page and iframe does its job well identifying and highlighting those fields.

Now I want to count the total number of said fields in a page as the user sees it, that is, including its iframes, and display this number over the browserAction icon (as adblock displays a count over its action icon).

My plan was to use setBadgeText in the action script to clear the current counter, then issue a tabs.sendMessage({req:"countFields"}) , and then let every content script respond to that message by getting the current value of the badgeText and increase it with the number of fields it found on its part of the page.

Well, that does not work well. I'm getting erratic values when a page contains iFrames. I guess this is a synchronization problem, when content scripts from different parts of the page try to get the badge value and update it.

I've also tried navigating through window.frames from a top level content script ( "all_frames":false ), but that won't work either, since cross script errors can prevent me from descending all iFrames (using the online version of tinyMce for example)

Well, at this point, I'm asking for help and advice on how to solve my problem. Any clue or pointer would be very much welcome !

I found the answer to that problem !

Since I believe knowing where to find for answers to a specific kind of problems (here, WebExtension development) is part of the answer, I give the link to that answer on the right place instead of just repeating here what was given me there.

https://discourse.mozilla.org/t/collect-infos-on-all-iframes-of-current-page-solved/30453

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM