Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is the initiator documented anywhere? How come the browser uses it to draw the page?


While the source looks like JSON, the page is still sent by the server as text/html. Browsers are so resilient to malformed markup that actually parse the content inside the <html> tag at the end of the document (firing the JS script that render the actual page), ignoring all the (pseudo) JSON around.

The page is rendered in QUIRKSMODE because the source is missing the <!DOCTYPE html> at the beginning of the document, to resemble valid JSON.

Well, at least that's clever!


Thanks for the explanation. It makes sense, but sounds very fragile.


yes, the initiator is a valid HTML with a `<script>` pointing to the script that receives the JSON and render the page. The interesting part is you can `fetch` the page directly and it will respond a valid JSON.


Once that script is kicked off it can get the current body of the page (the JSON) and replace it with html with:

    JSON.parse(document.body.innerText);
    document.body.innerText=""
    etc...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: