Represent a given Document. Any changes to its links will directly update the Document contents.
If the Document is prone to modification by any other scripts, you may want to use DomCloneResource instead, to make a clone of the Document and work on that one instead.
The Document this Resource represents.
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
config: GlobalConfigOptional environment configuration.
The HTML code of the document this Resource represents.
The document’s URL. Relevant for expanding any relative URLs it may contain.
Optional
config: GlobalConfigOptional environment configuration.
The Document object this DomResource represents.
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.
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).Get a DomResource representing the document inside an (i)frame element.
The DomResource instance representing the framed document.
An <iframe>
element or <frame>
element.
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.
DomResource represents an HTML document.
DomResource exposes the links of the document; both those links defined by attributes (e.g. an
<a>
’shref
or<img>
’ssrc
) and those defined in inline CSS (e.g. abackground: url(…)
in a<style>
element).DomResource.dry
attempts to capture the dynamic state of a DOM into its HTML, to make its HTML (available at string) a more accurate reflection of its current state. This includes, like with other Resources, expanding any relative URLs in links to absolute URLs.