On 26 juin, 18:31, Buterrip <
joaocassi...@gmail.com> wrote:
> Well Gildas, but i ask you, we are able to control a document only by
> injecting script,
Not really, content scripts can directly modify the DOM (but not
frames or parent).
> why we don't are able to control a frame by getting
> the frame without communication between them?
Because it's a bug (see Daniel link). A content script can't directly
communicate with its frames or parent. But, you can use background
page as a "proxy" to allow this kind of communication. In this case,
the background page can only rely on content script location.href to
establish the communication between content scripts. So, you cannot
send a message to a frame given its ID, index, name ... It will not
work for redirected frame content neither.
> I think i will be not
> able to comunicate with the frame too. It's a bug?
Injecting a script using "window.postMessage" as illustrated in my
example is a workaround for the bug described above. Thus it's
possible to communicate with a frame (or parent) given its ID, index,
name... In this case, the background page is not involved.
In all cases, you must set all_frames:true in manifest.json (or
allFrames:true in "details" argument of chrome.tabs.executeScript
function).