'Js or jquery: open a url with mobile user agent

I need to open a url with a mobile user agent... similar to the inspect element setting iphone and the reloading to get the effect. Nevermind if is a window.open or a iframe, I accept every idea.

I've tried setting useragent and then reloading a window.open... but no. I've tried to get the html, setting user agent, replacing html in window.open but something is not rendered as "natural".

As for now, I am here:

let generatedSource = new XMLSerializer().serializeToString(document);

let previewWindow = window.open("about:blank", "previewMobileFrame", "width=400,height=800,resizable=0");

setUserAgent(previewWindow, 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/69.0.3497.105 Mobile/15E148 Safari/605.1');
previewWindow.document.write(generatedSource);

Or I am in open my url, change useragent, reload window.

But there are some SSI that are obviously not re-renderered... and I thing setUserAgent is not really working.

Short story: how can I emulate "inspect element and setting to iphone" of chrome, and reload in js or jquery? enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source