The inclusion of JavaScript code in the WPF WebBrowser Control does not support the use of the Object.freeze

When integrating JavaScript code into a WebBrowser Control in my WPF App, I encountered an issue with the function Object.freeze(), resulting in an error when running the application.

Here is how my .xaml file with the WebBrowser control looks:

<Window x:Class="TestWPFApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:TestWPFApp"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <WebBrowser x:Name="ProgressBarWeb" HorizontalAlignment="Left" Height="300" VerticalAlignment="Top" Width="300"/>
    </Grid>
</Window>

The HTML and JavaScript code is injected using the NavigateToString() method:

public MainWindow()
{
   InitializeComponent();
   //Example JavaScript code 
   var html = "<html><head><script>" +
               "var platformtypes = {"Attr1": 0, "Attr2": 1};" +
               "Object.freeze(platformtypes);" +
               "</script></head><body></body></html>"
   ProgressBarWeb.NavigateToString(html);
}

My current questions are:

  1. Which interpreter does Visual Studio 2017 use for interpreting JavaScript code?
  2. Is it possible to change or update the interpreter being used?
  3. Or am I overlooking something else entirely?

Answer №1

I successfully resolved the issue using the CefSharp library.

In my implementation with .xaml, I included:

<ContentControl x:Name="browserContainer" Height="300" Width="300" Content=""/>

And within the code snippet, I utilized:

var html = "<html><head><script>" +
           "var platformtypes = {"Attr1": 0, "Attr2": 1};" +
           "Object.freeze(platformtypes);" +
           "</script></head><body></body></html>";
var base64EncodedHtml = Convert.ToBase64String(Encoding.UTF8.GetBytes(html));
var browser = new ChromiumWebBrowser()
{
   Address = "data:text/html;base64," + base64EncodedHtml,
   RenderProcessMessageHandler = new RenderProcessMessageHandler()
};

browserContainer.Content = browser;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: Attempting to execute functions on a dialog before it has been properly initialized with jQuery

Whenever a user clicks on a link, my goal is to display a modal dialog with the response of a GET method fetched using AJAX. The code looks like this: HTML: <a data-rec="@Model.rec" data-seg="@Model.seg" data-det="@Model.seg" class="btn btn-default ch ...

Is there a way to determine in JavaScript whether an HTML element contains no visible data, such as text or images?

In my web application, I have a feature that eliminates specific elements from a webpage. After the initial filtering, I am looking to remove all divs that previously held content but no longer do. For instance, after the first pass, an element may appear ...

State of buttons becoming active or inactive using jQuery

I'm encountering an issue with the jQuery code provided below: I have 3 buttons, which are defined as follows: <button class="btn btn-lg btn-primary" id="valider" data-actionname="appliquer" disabled>ok</button> <button class="btn bt ...

AngularJS $timeout function failing to update variable

I'm currently working on implementing a shaking animation for a button when it's clicked and the form fields above it are invalid. This is the snippet of code from the controller: if(valid){.. do valid stuff here ..} else{ console.log(this.sha ...

The scrolling on the image listing webpage is not as fluid as desired

I'm currently working on building a website for displaying images in Angular, similar to Google Photos. The site includes a custom scrollbar that displays the month and year. I want the image list to scroll when the user moves the scrollbar thumb. Her ...

Utilizing TypeScript generics to accurately extract type information from state during reduction

In the context of a state reducer presented as follows: const anObject = { fruit: 'Apple', today: new Date(), } function reducer(state, stateReducer) { return stateReducer(state); } const fruit = reducer(anObject, state => state.fruit ...

SendGrid SendEmailAsync() - unexpected error raised

Regarding the closure of this post by the moderator, I would like to clarify that it is not a generic null reference question; it is specific to SendGrid. I have tried to adhere closely to the documented SendGrid usage: public async Task<string> Sen ...

What is the best way to dynamically load a URL into an iframe's src attribute using onkeyup event triggered by an input field of type "url

For my video embed tool, I want to create a preview section. I have an iframe and an input field: <input onkeyup="javascript:youtube();" onchange="javascript:youtube() ;vimeo(this) ;videotome(); setsrc();" id="url" required type="url" placeholder="Ente ...

Uniquely Named Assemblies for Every Targeted Platform

I would like to create unique assembly names based on the platform target selected. For instance, if I have a console application named "bob.exe", instead of compiling for AnyCPU, I want to specifically compile for x86 and x64 resulting in "bob32.exe" and ...

Error encountered in Selenium Webdriver: A duplicate key has been detected and added to the collection

Looking for advice on how to avoid the error message: "An item with the same key has already been added." Can anyone help? I have two tests that pass individually, but when I run them all at once in Visual Studio, I encounter this error. [Binding] public ...

Issue with scoring quizzes in NodeJS

Hey there! I've created a quiz website using the "MEN stack" (sans React), and you can check out the repository link here. During local testing, the quiz functions as expected with no issues. The scoring is executed upon form submission, where I comp ...

Is it possible to update a MobX state when a message is received from Firebase in the background?

I've set up Firebase in my project like this: import { initializeApp } from 'firebase/app'; import { getMessaging, getToken, onMessage, isSupported } from 'firebase/messaging'; import store from './flag'; ...

React JS issue with SVG linearGradient not displaying accurate values

Within my component, I am working with SVG paths and a linearGradient value passed down from the parent component through static data. The properties 'startColor' and 'stopColor' are used to define the gradient colors for each element. ...

Tips for updating the value of an input text field in one HTML table according to a certain value entered in a different input text field located in another HTML table

I am working with an HTML table that consists of one row. Within this row, there are two TDs which each hold their own tables (each containing 10 rows with 10 input fields). My goal is to update the value of another corresponding text field based on change ...

Incorporate the UserId property to establish identity within my domain entity

I am facing a challenge in adding the UserId property from my ApplicationUser to the Player entity within my domain. Within my Player domain entity, I have a virtual ApplicationUserId property. My initial thought was to set the UserId after creating a use ...

Effortlessly deleting a row with JQuery and PHP without reloading the page

I am currently working on creating a jQuery function to delete a div, but I'm facing an issue. Whenever I click the submit button, the div is not being removed and the page gets refreshed. How can I achieve this without refreshing the page? You can ...

Error in Next.js: react-dom.development.js?ac89:14906 - Hook call is invalid. Hooks should only be used within a function component's body

Here is the code snippet I am working with: <div onClick={(e) => handleClick()}>Join Us</div> This is the handleClick function in my code: const handleClick = () => { console.log(Lang.getLocale()) }; And this is the Lang class metho ...

Is it not possible to use array splice with a string that is in array format (i.e., split string

Why doesn't array splice work with a string that has been formatted into an array using the split() method? function _formatText(text) { var textList = text.replace(/\s+/g, ",").split(","); return textList.splice(1, 0, "<br />").join ...

The slideToggle() function appears to be malfunctioning when sliding up or down, as it

Currently, I am in the process of creating a dropdown menu. However, I am facing an issue where the menu does not slide down or up smoothly when clicked. The animations seem to be delayed or non-existent. $('.menu-vertical .nav-menu > li'). ...

Ways to troubleshoot and resolve the jQuery error with the message "TypeError: 'click' called"

I am currently developing a project for managing Minecraft servers, focusing on a configuration panel. I have set up a form that users need to fill out in order to configure the settings and send the values using Ajax. However, I encountered an error: Type ...