dotnet api and vue client detect close browser / tab - vue.js

I have a client written in Vue.js and an API written in .NET core, the API also expose the static pages of the distribution of the vue.js client, the all thing is running on localhost and will stay that way.
When the server is up and running it's also opens a browser tab with the website URL on localhost, I made that with 2 methods: launchBrowser in the launchSettings or using Process.start(URL).
I would like that when the tab is closed the server will shutdown as well.
I have tried the following methods:
getting the process of the tab and detect close ( but every browser handle the tab process differently) - didn't work
using beforeunload and unload event in the client and send HTTP GET request to the server:
created() {
window.addEventListener('beforeunload', () => {
const request = new XMLHttpRequest();
request.open("GET", URL, false);
request.send();
});
}
it didn't work
check in the visual studio Tools -> Options -> Web Projects "Stop debugger when browser windows is closed, close browser when debugging stops", but when I publish the application the settings and launchSettings is not working ( only in the IDE )
Anyone have any idea on how to solve it?

You could try the following strategy
Create a separate launcher script.
The Launcher script launches the server in the background and stores it PID.
The Launcher now spawns a browser-process in foreground/blocking mode.
When the browser is closed (all tabs are closed) it will return control to the launcher script
Now you can kill the server with the PID you stored previously.

Related

How can I debug a websocket connection?

When running within a testcafe test, upon loading an app that tries to connect to a websocket, I receive an error in the console of "Connection closed before receiving a handshake response"
This prevents most of the app from working.
How can I get additional information about what the final request that testcafe is making after url-rewriting? I'd like to see exactly what url & headers it's sending to try to connect.
Simple example:
import { ClientFunction, Selector } from "testcafe";
fixture`Getting Started`.page("https://torus.qa.argos.education/session/new");
test("Example error", async (t) => {
await t.debug();
});
I've tried chrome with both non ssl and self signed certificate mode, and also tried disabling web security. Firefox gives the same error.
We released a new TestCafe version (v2.3.0), which includes experimental proxyless mode. This mode uses native browser automation. In Proxyless mode, a few issues are already fixed. This issue should also be fixed in Proxyless mode.
Unfortunately, I was not able to test your web site since the URL you shared is no longer available. Would you please check if your sample is working correctly in v2.3.0 with experimental proxyless mode enabled?
This option is available in all interfaces:
// Command-line
testcafe chrome tests --experimental-proxyless
// Programmatic
const testcafe = await createTestCafe({ experimentalProxyless: true });
// Configuration file
{
"experimentalProxyless": "true"
}
Please keep in mind that this mode is still experimental and is implemented only in Google Chrome. It will not work correctly if you run tests in a non-Chrome browser or in a combination of other browsers.

How to open a web browser when my windows service starts?

I have a windows service that needs to automatically open a web page when it starts
This is what ive tried
System.Diagnostics.Process.Start("iexplore.exe", "")
2nd
Process.start()
Both these options work when you debug but they do not physically open the webbrowser when running the service
I eventually used c.method = "POST" and it worked

Web app not responding on localhost:5000 when run standalone

I have simple DotNet Core app that runs fine with dotnet run but when I do dotnet publish and then dotnet HelloWorld.dll (in the bin/Debug/netcoreapp1.1 directory; same with bin/Rebug/netcoreapp1.1), on my local machine, the command prompt says "Now listening on: http://localhost:5000" but the service is not responding when I navigate to that address with my browser. Are there any kind of logs to review?
I reproduce the same in Windows 10 and OSX 10.11, both with clean dotnet new -t web projects, without any modifications.
In Windows I ran netstat -noa | find "LISTENING" and can see port 5000 at the bottom of the list. But still no connection when I try.
Ideas?
The browser output is:
The localhost page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500"
I run .Net Core 1.1.0 - SDK 1.0.0 Preview 2.1-003177 on both the Windows and Mac machine.
Click on the ^ icon of your toolbar to see hidden icons. If IIS is running, you will be able to see each instance and the port that the instance is listening on
I got the same error. To diagnose the error, I started up the app not in IIS Express but in what I think is a self-hosted option that opens in a console window.
If you look through the log in the console window, you might see an error in that log.
Also, I've noticed that sometimes the browser window pops up and navigates to the URL before the host environment is ready to handle the request. All you have to do when you get this error is wait a second and refresh the page, and the host environment will be ready and the page will load.

Is there a bug with Worklight on IE 10?

I've been working with a business partner to get an insurance app working on a Windows 8 tablet and have come across some interesting behavior that I can't explain.
I have managed to recreate the problem using a very simple use case and it appears to fail in the browser as well as when deployed as an app.
To re-create
Create a simple WL Hello World app with no JavaScript libraries
Deploy it to the development server
Open up an IE 10 browser and launch the WL Console.
Run this app using "Preview as Common Resources" and it should work fine (showing the default Hello Worklight)
click F12 to launch the IE debugger and then refresh the browser, click on the show console button to verify there were no errors
Add a WL.Client.connect(...) call into the wlCommonInit method
...
WL.Client.connect({
onSuccess: function(data) {
console.log("connection Successful");
},
onFailure: function(err) {
console.log("Connection FAILED: " + JSON.stringify(err) );
}
});
Save and re-run the app and it fails with an InvalidStateError (verify with F12 debugger)
Open up either a Chrome or Firefox browser to the WL Console page and click the "Preview as Common Resources" and open the developer tools for either and the console shows the connect call succeeding.
Is this a known problem or is there something that I've missed?
The ultimate goal is to deliver a Windows 8.1 tablet app however every time we tried to run the app it failed with this error. After some debugging I thought maybe it has something to do with the OS and tried to replicate it in just the browser with minimum code.
Through testing I've found that the basic Hello Worklight app with a WL.Client.connect() fails on IE but works on other browsers.
So I'm thinking if I get it working in IE browser, then that fix will be good for the tablet app as well.
Any pointers or guidance would be appreciated.
Note I am using WL v6.2 (6.2.0.00-20140915-1601)
Tested on Windows 7 - IE 10.0.9200.17089
Tested on Windows 8.1 - IE 11.0.9600.16663
The error I get is
HTML1300: Navigation occurred.
File: index.html
wlclient init started
before: initOptions.onSuccess
Request [/Connect/apps/services/api/Connect/common/init]
console.trace()
at __log (http://192.168.80.167:10080/Connect/apps/services/preview/Connect/common/0/default/worklight/worklight.js:4882:31)
at Anonymous function (http://192.168.80.167:10080/Connect/apps/services/preview/Connect/common/0/default/worklight/worklight.js:5240:7)
at createRequestHeaders (http://192.168.80.167:10080/Connect/apps/services/preview/Connect/common/0/default/worklight/worklight.js:3200:17)
at sendRequest (http://192.168.80.167:10080/Connect/apps/services/preview/Connect/common/0/default/worklight/worklight.js:3266:18)
at initialize (http://192.168.80.167:10080/Connect/apps/services/preview/Connect/common/0/default/worklight/worklight.js:3172:17)
at klass (http://192.168.80.167:10080/Connect/apps/services/preview/Connect/common/0/default/worklight/worklight.js:524:4)
at sendInitRequest (http://192.168.80.167:10080/Connect/apps/services/preview/Connect/common/0/default/worklight/worklight.js:7870:5)
at connect (http://192.168.80.167:10080/Connect/apps/services/preview/Connect/common/0/default/worklight/worklight.js:7879:3)
SCRIPT5022: InvalidStateError
File: worklight.js, Line: 1055, Column: 3
Uncaught Exception: InvalidStateError at (compiled_code):1055
For future readers, this problem was resolved by moving to a newer fixpack release v6.2.0.00-20141002

Why i cannot quit my node-webkit app

i'm building a node-webkit application i have made a link to quit
<span onClick="func App.quit()" title="Close">X</span>
but when i click it it says
Uncaught ReferenceError: require is not defined
What i am doing wrong here?
i do not understand why i am getting this error
i did added
var gui = require('nw.gui')
gui.quit()
</script>
i have to say in my packjage.js i open a url so all the javascripts are loaded from that url those javascript are not local on my device
The quit API is gui.App.quit() but not gui.quit().
Node-Webkit has 2 JS context, so if you use <script> tag to load JS from remote site, it will run in browser's JS context, as we know, require works in Node.js context. Read this page to get more info.
as tinyproxy already mentioned, use require('nw.gui').App to manage application lifecycle. to minimize window and other window operation as well as listening to window-related events, use require('nw.gui').Window.get() as described here: node-webkit Window. For example, to minimize current window:
var gui = require('nw.gui');
var win = gui.Window.get();
win.minimize();