I have a web app running locally at http://localhost:3000/. I started with the CefSharp.MinimalExample.WinForms project, pointed it to this URL and the app starts up successfully. My next step was to test out the C# <-> JS bridge to see how those calls work.
I followed the How do you expose a .NET class to Javascript? documentation and have the .NET side set up to have a class that can be called by JavaScript. The next step is to call CefSharp.BindObjectAsync in JavaScript to initiate the binding, but on my site CefSharp is undefined on the JavaScript side. The error in chrome I receive Uncaught (in promise) ReferenceError: CefSharp is not defined. My understanding of CefSharp is that it will bind the appropriate CefSharp methods to the window object so that it can be accessed from the JS side. Will this not work if I'm accessing a remote site that isn't included in the actual .NET project? It seems like I'm missing something stupidly simple, but after a few passes through the docs I am still stuck.
I had copied pieces of my Program.cs from this file. I misunderstood the purpose of BrowserSubprocessPath and left it in there. After removing that setting I can get to the CefSharp object in JS. My guess is that this setting was initializing the CefSharp object in the wrong place.
Doc on BrowserSubprocessPath:
// The path to a separate executable that will be launched for sub-processes. By
// default the browser process executable is used. See the comments on Cef.ExecuteProcess()
// for details. Also configurable using the "browser-subprocess-path" command-line
// switch. Default is CefSharp.BrowserSubprocess.exe
Related
I maintain an SAP Fiori app that has been running for two years without any problems. After upgrading SAPUI5 from 1.56.x to 1.101.x, there are various errors that can be traced back to a place where I try to load data for a JSON model.
The error is:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'indexOf')
This is the code:
onAfterRendering: function (oEvent) {
var sButtonId = this.getModel("misc").getProperty("/ButtonId");
// ...
// Here the code breaks because the variable is undefined:
if (sButtonId.indexOf("Demand") > -1) {
//...
}
},
The error usually only appears when navigating to the app from the SAP Fiori launchpad. If you reload the app itself, 99.9% of the time no error occurs.
There is no call that describes or reads the variable beforehand. The error appears directly at the first use.
I was trying to debug the UI5 framework a bit and came across internal method JSONModel.prototype._getObject:
When I call the app directly, this method returns the appropriate data and the app works. When I call the app from the launchpad, the method returns null. The model has not been loaded yet (oNode === undefined).
I then looked at the network and found that when I call the app directly, the JSON file/model has already been loaded before the above function is called, whereas when I load the app from the launchpad, the JSON file has been requested but no content has been served yet.
So it seems to be an asynchronous problem. I cannot use async/await, because UI5 officially only supports ECMAScript 5 (ES5) and we cannot deploy otherwise.
The model is declared and preloaded via the app descriptor (manifest.json).
Same as a/61879725 or a/63892279, you'll need to refactor the code by using dataLoaded1 from the JSONModel to ensure that the data have been loaded:
// Given: JSONModel and data source declared in the application descriptor (manifest.json)
thatJSONModel.dataLoaded().then(function() { // Ensuring data availability instead of assuming it.
var sButtonId = thatJSONModel.getProperty("/ButtonId"); // sButtonId is now defined.
// ...
}.bind(this));
Btw. I'd strongly discourage applications from relying on onBeforeRendering/onAfterRendering since it's unpredictable for them when and how many times the framework or a control initiates rendering.2
1 API Reference: sap.ui.model.json.JSONModel#dataLoaded
2 For example, the recent commit 8e24738 reduces the number of render calls in applications.
I'm facing an issue while debugging my application. Following is the architecture:
Server: Java (Servlet)
Client: React+D3
Problem: Whenever, I change some react or d3 code and if an error occurs then it just shows me that some react (or d3) error has occurred but never tells me which function the error occurred (as seen in snapshot). Now, I know that simply debugging it by having the information like variable name and searching where I defined that variable. However, situation becomes tough when I use same object multiple times (say window) and had made several changes in the code. In this case, a specific line number where the error occured can be handy and quick. Let me know if I'm missing some basics about debugging such applications?
EDIT1:
1. In the snapshot, http://localhost:8080/..../Server Server is the main servlet application, kind of launchpad, which triggers several other react-based js files.
2. The mentioned ReferenceError is inside a function updateWindow() but the console never mentions this (and that's my problem).
PS: I'm using Eclipse tomcat on server-side
I think there's no straight forward solution to this problem. So, I'll post the method that worked for me with few additional points:
Problem: It doesn't gives a nice error trace like standard Java application, probably because it mixes with JavaScript code.
At every line of the error trace, line:column specifies the error line. I used this as a reference and started manual debugging from where my application launches i.e. Server.java and look where I defined the createChart() in the JS file and drill-down until I found the referenced variable.
In case of ReactJS' error (an error after resolving reference issue), I debugged it with normal react.js (not minified version react.min.js) so that it shows me exact line of error. Minified version is cluttered and is useless while debugging.
PS: If someone has better answer I'll edit this in future.
I am new to GWT and trying to create a small application. I am currently assembling a small framework for the app, a generic layout handler, etc. This may not be the last problem I will bump into, but I just cannot find any solution to this on google.
So I have a class type, which return me Composites. Also, I have another one, which stores these kind of classes in Stack (I also tried Vector, I thought maybe GWT has issues with it). It didn't matter. If I call the .clear method on the Stack, I have the aforementioned error in the inspection menu of Chrome:
Uncaught TypeError: Cannot read property 'clear_31_g$' of undefined
Like if GWT does not know, how to convert this method to javascript or what? Do you know what is the problem here?
eclipse neon, Java 7 setting on Java SDK 1.8 (maybe this?), GWT 2.7.0 and App Engine 1.9.34
Thanks!
edit1: I also found the page, which contains the emulated JRE classes' list (http://www.gwtproject.org/doc/latest/RefJreEmulation.html) with all supported methods. Now I see, that clear is not on that list for Stack, but empty does and that gives me the same error. :-/
This error simply means that you try to call the clear() method on a null object (the object is undefined).
The error message itself is not as clear as it could be. First, it's not always about reading a property but also about calling a method. Second, remember that you run a compiled to javascript code and the property (or method) name may differ from the original one - it has something like _31_g$ added in the runtime.
We have some QUnit javascript tests running in Visual Studio using the Chutzpah test adapter. Everything was working fine until we changed our api (the one being tested by the js files) recently, and added some validations over the UserAgent http header. When I tried to update the tests to change/mock the user agent I realized it was not directly possible even by overriding the default browser property.
After a few days of scavenging, I finally found what exactly is happening. Chutzpah is creating a phantomjs page object for the test files to run on. This is being done on a base javascript file (chutzpahRunner.js) located at the Chutzpah adapter installation path. These are the last lines on the file, that effectively start the tests:
...
// Allows local files to make ajax calls to remote urls
page.settings.localToRemoteUrlAccessEnabled = true; //(default false)
// Stops all security (for example you can access content in other domain IFrames)
page.settings.webSecurityEnabled = false; //(default true)
page.open(testFile, pageOpenHandler);
...
Phatomjs supports changing the user agent header by specifying it in the page settings object. If I edit this chutzpahRunner.js file in my machine, and manually set the user agent there, like this:
page.settings.userAgent = "MyCustomUserAgent";
My tests start to work again. The problem is that this is not in the project itself, and thus cannot be shared with the rest of the team.
Is it possible to change the properties of the phantomjs objects created by Chutzpah to run the tests? I'd like to either change them from inside my own tests, or from another script file I could embed on the pipeline.
Without a code change in Chutzpah it is not possible to set those properties on the PhantomJS object. Please file an issue at https://github.com/mmanela/chutzpah asking for this functionality and then fork/patch Chutzpah to add it (or wait for a developer on the project to hopefully get to this).
Update:
I pushed a fix for this issue. Once this is released you can use the following in a Chutzpah.json file:
{
"userAgent": "myUserAgent"
}
we have developed an Intranet Management Application with Silverlight 4. We have been asked to add the functionality to call a remote desktop tool which is installed on clients using the Intranet SL App. In an earlier version of the tool written in ASP.NET we just added a Javascript function to the aspx page like this:
function RunShellCommand()
{
var launcher = new ActiveXObject("WScript.Shell");
launcher.Run("mstsc.exe");
}
and called it from ASP.NET.
Now it's clear that SL4 is running in a sandbox and that I cant use the AutomationFactory to create a WScript.Shell object (out of browser mode is not an option).
I thought I could circle around the problem by, again, adding the RunShellCommand javascript method in the aspx page where the SL4 control is hosted and call it via
HtmlPage.RegisterScriptableObject("Page", this);
HtmlPage.Window.Invoke("RunShellCommand", "dummydata");
from my ViewModel. When I run the Application the debugger just skips the RegisterScriptableObject method and quits. Nothing happens.
My question is if am doing something wrong or if this just wont work this way.
Is it possible that I cant do a RegisterScriptableObject from a viewmodel?
EDIT: When I explicitly put a try, catch block around the two methods I get an ArgumentException from the first method stating that the current instance has no scriptable members. When I delete the first method and only run the Invoke, I get a browser error stating that the automation server cant create the object. So is there really no way (except OOB mode) to do this?
Yes, the explanation is correct: you should add at least one method with the ScriptableMember attribute in order that you can use the RegisterScriptableObjectmethod. But it is used only for calling C#-methods from JavaScript.
As far as I see, you want to do the opposite: to call JavaScript code from the Silverlight application. Then you need only one line:
HtmlPage.Window.Invoke("RunShellCommand");
The error automation server cant create the object has nothing to do with Silverlight. I'm sure that if you call the JS function directly - the error will remain.
According to the internet, the reason might be not installed Microsoft Windows Script. Or it is because of security restrictions of the browser.