nsSubDocumentFrame::BuildDisplayList could check if the relevant browsing context is for image document. I think BrowsingContext::GetSyntheticDocumentContainer() could work there.
Bug 1909584 Comment 9 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
nsSubDocumentFrame::BuildDisplayList could check if the relevant browsing context is for image document. I think BrowsingContext::GetSyntheticDocumentContainer() could work there. Hmm, focus handling is still unclear.