Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is this?
As per #396, when a same-origin frame is serialized, all of its content becomes relative to the frame parent, which can then result in invalid resource URLs. Like the issue suggests, we can transform the URLs within the frame document to be fully qualified URLs based on the frame document's URL.
During the recursive DOM serialization, we can provide a custom transform function to be applied to iframe documents after cloning but before the function returns a string. In this transformation we can then find all relevant elements to transform their respective URLs.
According to HTML 4/5 spec the
href
,src
,srcset
,poster
, andbackground
attributes are attributes that may contain URIs (and that we care about transforming). Most attributes' property counterparts are already resolved, however that is not always the case (such asbackground
). Thesrcset
property is also not resolved, and requires parsing to properly replace URLs within the list of image candidates.In addition to those attributes, CSS within
style
elements or inlinestyle
attributes may also contain URLs using theurl()
CSS function and therefore are also transformed.In adding a test, Karma complained about assets being missing. I found a workaround by setting a
proxy
option to a semi-valid URL so it doesn't proxy and doesn't log. If logs crop up in the future, we probably want to host a single fake asset to silence them.Fixes #396