Is WebView behavior identical to Safari - macos

Our Mac OS application displays user interface inside WebView component.
Can we rely on the fact that WebView behaves exactly as Safari content pane on any Mac?
Can we expect the same set of plugins installed in Safari and inside WebView of our application?
In other words, is the same WebView shared by all applications on Mac OS, including Safari?

Quoted from apple docs:
A WebView object is intended to
support most features you would expect
in a web browser except that it
doesn’t implement the specific user
interface for those features. You are
responsible for implementing the user
interface objects such as status bars,
toolbars, buttons, and text fields.
For example, a WebView object manages
a back-forward list by default, and
has goBack: and goForward: action
methods. It is your responsibility to
create the buttons that would send
theses action messages. Note, there is
some overhead in maintaining a
back-forward list and page cache, so
you should disable it if your
application doesn’t use it."
A WebView uses webkit engine to render html which is what safari also uses. Hence most of the functionality will be the same.

Related

Open certain links in external browser using Nativescript

I am working on a simple app written in Nativescript.
The app has a login form that authenticates against an API, and on success loads a webview. So not that complicated.
But I would like to be able to open certain links in the default browser on the phone, and not in webview, like links to external sites.
Is it possible to "capture" all link clicks, and if the link has the target attribute set to blank, we make the link open in a external browser?
I need a solution that works both on iOS and Android.
Is this possible to do in Nativescript?
Yes, it's possible to do that in NativeScript but not with the default WebView component. I was exactly in this situation, what I did is writing a plugin that customizes default WebView in NativeScript to override the default WKUIDelegate in iOS webview & idem for Android.
For iOS, the WKUIDelegate allow to detect if any attempt to open link with target _blank with method webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures, hence, when implementing your custom webview with this delegate allow to open link in external browser / application as you wish.
Take a look at this plugin: https://github.com/Notalib/nativescript-webview-ext to have an idea how to customize default webview.
You may use the nativescript-webview-ext plugin and use the shouldOverrideUrlLoading event to check the URL and cancel the process as needed then use the open url method in utility module to open the given url in default browser.
You can import this
import * as utils from "#nativescript/core/utils";
and then do
utils.openUrl("https://www.youtube.com/");
whenever you want to open a link (in this case youtube) in a default browser.

High Sierra WebView blocks anchor tag navigation

I have a Mac app that displays info in a WebView. Quite an old app now and in Objective-C which I am rapidly forgetting.
The WebView contains anchor tags to allow navigation within the pages, both by clicking on links in the page displayed, or by clicking tabs in the UI which send Javascript to the WebView. In High Sierra this no longer works although it displays no error.
It appears that I need to implement isKeyExcludedFromWebScript: but my attempts to do so have failed.
Do I need to sub-class WebView? Putting isKeyExcludedFromWebScript: and isSelectorExcludedFromWebScript: in the View Controller containing the WebView doesn't work - they never get called.
If anyone has any advice or examples, I would be most grateful.
I am afraid that the answer will be to upgrade the app to use WKWebView but I was hoping for a quick work-around until I get time to do that.
Answering my own question here as I have worked out a solution.
The problem was that I was loading an HTML string into the WebView and when I tried to use internal navigation links, it didn't have a base URL to use as a prefix and so the anchor navigation never worked.
It used to work, prior to High Sierra, so there must be something new about how WebViews operate.
The solution was to save the HTML string to a temporary file and have the WebView load that file's URL instead of loading the string directly.
This applies to both WebView and WKWebView.

Disable browser controls in CEF

Just a quick question.
I saw some pictures of chromium embedded (CEF) implementation in Win32 and there is everywhere those browser buttons "Back" "Forward" "reload" and address bar (http://img300.imageshack.us/img300/6443/acidc.png).
Question is: Is it part of win32 application or part of CEF itself, and before I start to dig in CEF i need to know can I turn off all those buttons and use CEF only to show a window with web page in it, without any controls? (or make adress bar read only and hide all other controls).
Want to use CEF because chromium engine fast and supports all modern technologies.
You need to modify SetNavState inside client handler implementation.
Also, for the context menu, you need to implement menu handler method OnBeforeMenu to enable/disable the Back/forward as well.
Navigation buttons and address bar it is part of cefclient sample application, not of browser itself.

Any way a native application can access the DOM inside a browser? (Mac/Win/Linux)

Think of a dictionary application that grabs words upon user's click from any other application (including browsers) and pops up it's meaning. Is it possible to twist this behavior based on the word's HTML attributes?
Edit: I noticed something cool. OSX's built-in dictionary app has a shortcut (cmd+control+d) that actually pops up a word's meaning (the word you're hovering your mouse above). It also highlights the word. The highlight area grows as you increase the font size. check out this fiddle and try various font sizes.
Yes/no
If your dictionary application embeds a browser instance (like a webkit browser) then it should be possible to access the DOM.
If you want your application to manipulate an already running browser instance it has no control over then it could probably done if
that browser has a browser plugin that interacts with your application
you intercept low level commands to mess directly with the kernel or the memory of the browser.
Neither of those are easy to do for all browsers.

Retrieve HIViewRef from dialog

Is there any way to retrieve a HIViewRef reference from a Dialog (similar to HIViewGetRoot) in order to use it as a browser using WebKit API?
Thank's for all.
Assuming you're using modern NIB-based dialogs (and not the ancient resource-based stuff with Dialog Manager calls), there's basically no difference between a "dialog" and a "window", so the "HIViewGetRoot" technique applies in dialogs too.
(and if you are still using resource-based dialogs, check out the upgrading to the Mac OS X HIToolbox document, because you'll need to use NIB-based compositing windows if you want to embed a WebView in Carbon.)

Resources