WebView2Samples icon indicating copy to clipboard operation
WebView2Samples copied to clipboard

Question: Object.freeze(Object) usage within sample

Open jaredperreault-okta opened this issue 2 years ago • 2 comments

The "most basic" sample Win32_GettingStarted includes this line

// <Scripting>
// Step 5 - Scripting
// Schedule an async task to add initialization script that freezes the Object object
webview->AddScriptToExecuteOnDocumentCreated(L"Object.freeze(Object);", nullptr);

This line of javascript freezes the Object prototype, making it immutable. This causes any website which includes polyfills that extend the Object prototype to throw an error (and presumably not render anything). Polyfills are common place in web development. (More details https://github.com/MicrosoftEdge/WebView2Feedback/issues/2035).

Is there a specific reason this sample recommends freezing the Object prototype?

jaredperreault-okta avatar Feb 24 '23 16:02 jaredperreault-okta

This code is just an example of injecting script, not a recommendation. I've opened a bug on our side to consider making the example more clear and less intrusive. Thanks!

champnic avatar Feb 28 '23 20:02 champnic

This very line seems to have made it into production for the MS Remote Help client (confirmed by debugger). We're having trouble with polyfills, too.

tmackay-cenet avatar Jan 24 '24 22:01 tmackay-cenet