1

tl;dr: Is there a reflective/introspective mechanism to query live objects for their capabilities?


The protocol is vast, but certain parts only apply to certain types of targets (e.g. 'Page.captureScreenshot' will fail on an iframe target). At first, I thought maybe target types matched up 1-to-1 with a domain, but, while there is a Page domain, there is no IFrame domain.

I noticed the Schema domain, which sounded promising if directed to a session for a particular target, but it is deprecated.

Sean DeNigris
  • 6,306
  • 1
  • 31
  • 37

1 Answers1

1

iframe is not a target, it has a frameId property to its node and not a targetId (that happens to also be the frameId of the main frame).

Regarding the specific issue you have - if you know the nodeId of the said iframe, do the following (Assuming iframeNodeId is known):

  1. Using DOM.resolveNode, that is documented here get the objectId of said iframe.
  2. Using Runtime.callFunctionOn, like documented here with the objectId of the iframe, run a function returning the boundaries of the iframe (using getBoundingClientRect documented here.
  3. Using Page.captureScreenshot as CDP defines here, you can now set the clip argument to a Viewport you can calculate easily from the info we got back last time (we just need x, y, width and height.
Kle0s
  • 113
  • 1
  • 8
  • 1
    Thanks! I ended up moving to Playwright (as suggested by the DevTools docs), which is higher level and supports other browsers as well. I appreciate the solution to the particular example, but my question is really whether one can query live objects about their capabilities and avoid having to piece that info together from docs and other outside sources. I upvoted your answer and updated the question. – Sean DeNigris Feb 16 '22 at 14:43