Bug 231375 - DOMParser broken in iOS 15
Summary: DOMParser broken in iOS 15
Status: RESOLVED DUPLICATE of bug 231138
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: Safari 15
Hardware: iPhone / iPad Other
: P2 Critical
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-07 10:56 PDT by erik.witt
Modified: 2021-10-11 10:04 PDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description erik.witt 2021-10-07 10:56:11 PDT
As describes in this ticket https://bugs.webkit.org/show_bug.cgi?id=231138 there is an issue where XHR with response type document does not parse and return a document despite a successful response from the server.

The bug however seems to span further. When I tried the workaround to fetch a text response via XHR and parse it with DOMParser, I discovered that this one is broken in some scenarios as well since it seemingly parses parts of the document but not all. 

This only happens on iOS 15 (iPhone 11 pro max for me)

Steps to reproduce:
1. Go to www.decathlon.de on your iOS 15 device
2. Use remote debugging to be able to use the console
2. Execute the following script
```
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open('GET', 'https://www.decathlon.de/browse/c0-alle-sportarten-a-z/c1-fahrrad-welt/c3-mountainbike/_/N-obq78x', true); 
xhr.responseType = 'text';

xhr.addEventListener('readystatechange', () => {
  if (xhr.readyState === 4) {
    console.log('Success')
    const parsedDocument = new DOMParser().parseFromString(xhr.response, 'text/html');
    
    console.log('Document')
    var scripts = Array.from(parsedDocument.querySelectorAll('script')).filter(s => !s.src)
    var lastScript = scripts[scripts.length - 1]
    console.log(lastScript.textContent);
  }
});

// Handle errors of XHR connection
xhr.addEventListener('error', (e) => {
  
    console.log('Error', e)
});
xhr.send();
```

The script print the content of the last inline script in the DOM. The script's content that is printed to the console should start with the line `var cube = cube || {};`. On iOS 15 Safari it starts with `window.fux = window.fux || {};` which is not the last inline script in the document!

If I print the whole string document to the console, I get the complete HTML text, also when I print the document object to the console, I get the full DOM. Only if I access the DOM by querying all the scripts for example it seems that there is half of the DOM missing.

On MAC OS Safari 15 it works without issues.
Comment 1 Alexey Proskuryakov 2021-10-11 10:04:40 PDT

*** This bug has been marked as a duplicate of bug 231138 ***