Hard browser refresh using nwjs on Mac - nwjs

Is there a way to do a hard browser refresh when running an app with nwjs, on Mac? nwjs's right click 'simulate browser restart' seems to start the app at its entrypoint again. Is there a way to simulate the behavior of simply clicking the shift reload button in Chrome?

There is an nwjs api for this:
// Load native UI library
var ngui = require('nw.gui');
// Get the current window
var nwin = ngui.Window.get();
// this will do a hard refresh
nwin.reloadIgnoringCache();
// here's a regular refresh
nwin.reload();
nwjs doc:
http://docs.nwjs.io/en/latest/References/Window/#winreloadignoringcache

just use javascript reload
location.reload();

Related

macOS native coding with browsers, how to open a url in existing tab from obj-c/swift?

I've developed a command palette for macOS. Over the last few days I've figured out a way to show the Notification Center inside my app.
I would like to mimic the behaviour of the real Notification Center when clicking a notification: open the corresponding tab when clicking in a browser notification.
However whenever I cannot figure out a way to do it programmatically, I can only tell macOS to open the link and it automatically opens the default browser and creates a new tab.
let url = URL(string: "https://www.google.com")! // this opens a new tab everytime
if NSWorkspace.shared.open(url) {
print("default browser was successfully opened")
}
As for the notification itself I do get all the info it contains: the app bundle id, the notification payload, and even a link (e.g. n#https://web.whatsapp.com#465718293123#c.us). I've seen some answers that rely on AppleScript but I would rather avoid it if possible. But if not possible... then happy to fallback to it.
Any ideas how to achieve this? Many thanks!
P.D. I've also tried some variations of the link such as: arc://web.whatsapp.com#1234567 or arc://n#web.whatsapp.com#1234567. At most this focuses on the browser but not on the tab.

How to open url in Safari and the get back to the app under UITests in Xcode 7?

This is my custom view where "LondonStreet" is a button.
When I tap that button I get url and open it in Safari (it works). Then I can go back, using "Back to Wishlist" button (it also works).
The problem is when I try to test this under UITests.
itemsTable.cells.elementBoundByIndex(0).buttons["addressButton"].tap() //press the button to open link in Safari
Along with this line:
app.statusBars.buttons["Back to Wishlist"].tap() //go back, doesn't work, although it was recorded by Xcode itself.
is an error:
UI Testing Failure - Failed to get screenshot within 5s.
And also in issue Navigator
UI Testing failure - Unable to update application state promptly.
Starting in iOS 11 you can interact with other applications using the XCUIApplication(bundleIdentifier:) initializer.
To get back to your app you'd do something like:
let myApp = XCUIApplication(bundleIdentifier: "my.app.bundle.id")
let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
// Perform action in your app that opens Safari
safari.wait(for: .runningForeground, timeout: 30)
myApp.activate() // <--- Go back to your app
UI Testing cannot interact with anything outside of your application. In your scenario, the framework can no longer do anything once your app opens Safari.
To verify this, try printing out the app's hierarchy once Safari opens. You will notice that nothing in Safari nor the navigation bar will show up - you will only see your app's information.
print(XCUIApplication().debugDescription)
To open specific url in Safari on iOS 15:
safari.textFields["Address"].tap()
safari.textFields["Address"].typeText("www.urlToOpen.com")
safari.keyboards.buttons["Go"].tap()

When a user launches "new window" in a home screen app

When a user launches "new window" link in a home screen app.
In Mobile Safari this type of action would open a new tab. What happens if the app is on the home screen and has name="apple-mobile-web-app-capable", content="yes" active.
Will the window still technically be in another tab, although you cant get back to the original one - or will it just navigate within the current tab?
First of all, unfortunately window.open method does not work at all.
Instead, a < a href="..". >...< /a > works and by default launches Safari and opens the link in a normal browser window (so, if the user wants to come back to the app, he has to doubleclick the iPad key and switch back to it).
You can force the link to open inside the app (so replacing the current page) with the tricks listed here: iPhone Safari Web App opens links in new window
Hei, I found a brilliant way to have a "window.open" effect in an iOS webapp too!
It loads a page in a Safari tab and has solved my problem, maybe it can be useful to others: http://webdeveloper.com/forum/showpost.php?p=1161159&postcount=14
It's also a great way to avoid the popup blocker (the blocker would stop a window.open(url) call but it doesn't stop that method) :-)

Jquery img preload not working in FireFox

I recently did a small jQuery snippet that allows me to show a loading img until the real image is loaded.
The snippet seems to work in Safari, Chrome but not FireFox.
FireFox only displays a loading alt and never switches to the loaded image.
Here is the snippet
var loading = $('<img src="/media/ajax-loader.gif" alt="loading" />');
$('.thumbnail').each(function(){
var loadIMG = loading.clone();
$(this).after(loadIMG).load(function(){
$(this).fadeIn('fast');
loadIMG.hide();
}).hide();
});
Any ideas why?
You haven't said what exactly is happing on FF but below can be one of the problem. From jquery documentation
It is possible that the load event
will not be triggered if the image is
loaded from the browser cache. To
account for this possibility, we can
use a special load event that fires
immediately if the image is ready.
event.special.load is currently
available as a plugin.
Here's the link for plugin.
Edit:
Based on comments from load event, try below:
$('.thumbnail').each(function(){
var loadIMG = loading.clone();
$(this).after(loadIMG).load(function(){
$(this).fadeIn('fast');
loadIMG.hide();
}).hide();
if (this.complete) $(this).trigger("load");
});
Of course, the plug-in seems to be doing same thing along with handling some other scenarios as well as.

Closing an opened window on mobile safari with javascript?

In app mode, if I open a new window using javascript, the newly-opened window cannot close itself (on an on-click event) using the standard window.close() or self.close(). Does anyone know if there's an alternate method?
What I find most beguiling about this is that it goes against Apple's very own design guidelines: essentially a site has the ability to open a new window but the user cannot get out of it without closing the webapp using the Home button.
Any ideas? Thanks!
JavaScript:window.self.close() is how to do that.
you can try this js code snippet.
var win = window.open('','_self');
win.close();