The Document to clone.
Optional
url: `${string}:${string}`Since the passed Document already has a property doc.URL
, the url
parameter
is optional; if passed it will override the value of doc.URL
when determining the target of
relative URLs.
Optional environment configuration.
The clone of the Document.
The Document that was cloned.
URL of the resource.
A Blob with the current resource content.
The DOM as a string (the document's outerHTML
).
Get the Links that are found in the document; both those links defined by attributes
(e.g. an <a>
’s href
or <img>
’s src
) and those defined in inline CSS (e.g. a
background: url(…)
in a <style>
element).
It includes links directly contained in the document itself, as well as in its iframes with a
srcdoc
attribute (because such iframes are not treated as subresources).
The target of a Link can be modified, which updates the resource content accordingly.
However, even though the content of a link is ‘live’ (i.e. its target
is read and written
directly from/to the DOM), the list of links is created only at the construction of the
DomResource. Thus, if the DOM is modified afterwards, any newly created links will be missing
from this list.
A list of DomResources corresponding to documents in iframes with the srcdoc
attribute
(note that these documents are not considered subresources).
An array of Links (a subset of links), containing only subresource links, and
for whose subresourceType
a Resource subclass exists. That is, those links that fromLink accepts.
Create a DomCloneResource for each document in an (i)frame in the original document.
The created clones are associated with the (i)frame elements. To access a clone, use getContentDocOfFrame.
If true
, also clone any frames inside the frames, recursively.
Get the clone of the framed Document for a given (i)frame element.
As cloning a DOM does not clone the documents inside its frames (the contentDocument
of a
frame in the cloned resource is null), this method lets you obtain a clone of the framed
document.
On the first invocation, the frame content is cloned from the original document. Subsequent invocations will return this same object.
A clone of the document in the frame.
The frame element for which to get the inner document. Either the frame of the original or of the cloned document can be passed.
Make the DOM ‘dry’: try make its HTML represent its current state as accurately as possible.
Drying performs several transformations:
Resource.dry
).<noscript>
elements, and contenteditable
attributes are removed (by makeDomStatic).srcdoc
values are updated (by updateSrcdocValues).Static
fromCreate a DomResource from a Blob of HTML and a URL.
const response = await fetch('https://example.org/page.html')
const domResource = DomResource.fromBlob({ blob: await response.blob(), url: response.url })
A new DomResource, created by parsing the given HTML.
Optional
config?: GlobalConfigPerform a function on each subresource link.
A promise that completes when all invocations have completed.
Invoked on each subresource link.
Static
fromFetch the resource a given link
points to, and return it as a Resource.
This method does not modify the given link; the caller can store the created Resource in
link.resource
, to grow a tree of links and resources.
link.resource = await Resource.fromLink(link)
The newly created Resource.
The link pointing to the resource.
Optional environment configuration.
Static
getDetermine the Resource subclass to use for the given subresource type.
The appropriate Resource subclass, or undefined
if the type is not
supported.
The type of subresource expected by the parent resource, e.g.
'image'
or 'style'
. Note this is not the same as its MIME type.
DomCloneResource represents an HTML document, but works on a clone of the DOM it was given.
It allows a web page to be snapshotted in its current state, after which modifications to the original DOM or the clone do not influence the other.
The original document is cloned at construction time. Its frames can be (recursively) cloned with cloneFramedDocs.
See its parent class DomResource for further info.
Example