Access WebView2 newly opened window - chromium

If I run window.open("url") it will open url in new popup window, even if it is Edge WebView2. It will just have default Windows title-bar, and read-only url bar. I need to open url from WebView exactly in new popup window, via window.open("url").
Is there any way to access that window from my program as far as original WebView2 child-window? By accessing I mean injecting scripts, and getting js-response after injecting.
Or, at least, perhaps there is way to open url with some pre-injected script, like window.open("http://google.com -javascript: alert(5)")?
Update
Found MSDN article, probably this is what do I need. Trying to understand that.

Yes, the ICoreWebView2::add_NewWindowRequested event lets you intercept WebView2 opening new windows.
If you do nothing in the event handler, or don't subscribe to the event, you'll get a new popup like you describe. In script the return value of window.open is connected up to the newly opened popup window. But in your native code you have no access to or control over the newly opened window.
Or you can set the Handled property to true on the NewWindowRequested event's args, and no new window will be created. This is useful if you want to prevent opening windows or if you want to send new window opens to the default browser or somewhere else. In script the return value of window.open is null.
Or you can provide your own ICoreWebView2 via the NewWindow property. In this case you are responsible for and get to choose how to host that ICoreWebView2 in some manner. The ICoreWebView2 you provide as the NewWindow will be the target of the new window navigation and connected back up via script to the return value of the window.open call.
Because obtaining a new WebView2 may require asynchronous method calls, you can use the GetDeferral method on the event args to stop the completion of the window requested event until you call Complete on the deferral asynchronously later.
You can see a working sample of the add_NewWindowRequested event in our sample app.

Related

Dismiss dialog coming from outside my application

In my application I perform an operation which causes an internal Android app to pop up AlertDialog over my application.
Is it possible to somehow dismiss this Dialog programmatically? Unfortunately I can't find the access to this Dialog object.
I've tried overriding onCreateDialog() method in my Activity, but as my Activity is not an originator of Dialog window, this method is not being called when it pops up.
I was also thinking about getting list of all objects that appear on the screen, but I assume there's no such method?
To my understanding you are doing something that is requiring some user interaction, like bluetooth pairing, in which case this Dialog is brought up by the system... possibly (System Dialog) which is not controlled by you. To solve this...
One thing you can try is:
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
public static final String ACTION_CLOSE_SYSTEM_DIALOGS
Added in API level 1 Broadcast Action: This is broadcast when a user
action should request a temporary system dialog to dismiss. Some
examples of temporary system dialogs are the notification window-shade
and the recent tasks dialog.
Constant Value: "android.intent.action.CLOSE_SYSTEM_DIALOGS"

How to programmatically close a MessageDialog in Win8 app using WinJS?

Here is a similar question to mine regarding how to programmatically close a MessageDialog in a Win8 app, but the author of the question is using C#. I'm curious about how to solve the issue with WinJS. Is there any way to cancel a MessageDialog programmatically with WinJS without have access to the CommanUI objects within the dialog itself? I cannot simply invoke the handler associated with an appended CommandUI button since, in some cases, I wouldn't know which button index has that functionality.
Any tips?
Thanks!
MessageDialog.showAsync returns an IAsyncOperation<IUICommand> object and inherits from IAsyncInfo. The IAsyncInfo interface includes a cancel method which generically cancels asynchronous operations. In the case of the message dialog, calling cancel on the async operation will dismiss the dialog if it is still present.
var asyncOperation = messageDialog.showAsync();
asyncOperation.cancel();
More info on the WinRT asynchronous programming pattern can be found on MSDN.

C# webbrowser control: page opens new window but it won't work

I use a webbrowser control (in C# - latest version of visual studio and .NET) to allow me to read and write data to a specific web page. Everything is OK until I reach the point that the page attempts to open a pdf document in a new window (the page contains javascript code).
The new window opens OK on my IE. But nothing appears when the webbrowser control opens the new window...
I've tried setting firefox as my default browser to see if it makes any difference but no good came out of it. The webbrowser control still opened IE.
I've tried catching the event of the new window and refer the url to another webbrowser control... no success again!
How can I get the pdf document? And why would the new window open but not display the pdf?

NSWindow does not respond to keystroke command-s

It may be very simple, but I cannot find it:
I have three windows in three separate NIBs in my application. One is opened when a new document is opened, the other two can be opened from the program's window menu.
The problem is: two windows (in them the one that is opened at the beginning) accepts the normal keystroke as for example command-s for save, and the other one does not and gives a warning sound instead. I cannot figure out the difference between the two windows or their controllers. I know it will have to do with the responder chain, but I am left clueless.
Any ideas?
Check to make sure that the window's delegate is set to the window controller, and that the window controller implements -saveDocument: (or whatever action the Save item is connected to).
Windows don't respond to key combinations. Menu items do. In response to being pressed (whether using the mouse, using a key combination, or using Accessibility), the menu item sends its action message down the responder chain.
You get a beep when nothing in the responder chain responds to the action message.
Assuming that this is an NSDocument-based application and you've started Apple's doc-based-app template, the menu item's action is saveDocument:, and the NSDocument object is the object that responds to that message. When your document windows are active, their documents are in the responder chain, so the menu item that sends that action message is enabled. When your third window is active, the document is not in the responder chain; nothing else responds to that message, so the menu item is disabled.
This problem isn't specific to Saveā€”it affects all action messages that should go through to the document object. One important other example is Print: The user will probably mean to print the document, not the third window.
You've probably made this third window a kind of window that exists as a peer to the other windows. Besides this responder-chain problem you're having, the user will also probably not realize that they have left the document; they expect to still be able to do document things. Consider making it a utility panel instead.
If you really do have a good reason to make this window whatever kind of window it is, you'll need to keep the last-active document object in the responder chain when this third window becomes main, while at the same time handling the case where the window becomes main because a document window (possibly the last one) has closed.
Well, it turns out that I implemented the third window in a way where I created it with its controller using initWithNibFile, ran a procedure in the controller and then sent it a [window close] command because I did not want it to appear on the screen yet. That somehow took it out of the document-associated window, no idea why. No I migrated that specific called procedure into the document controller itself, treat the window like the second window and voila, it works again.

VB.Net Start-up window changes based on App.config setting, how is it changing?

I have this VB.Net 1.1 project that I have to make some changes to. There is a flag in the App.config file. If it is false, the page just loads a splash screen and runs the program normally. If it is true it first opens a login window.
VB.Net is not something I've ever worked with before. I can't for the life of me figure out where the logic for the picking the startup object is. In the property pages, Main.vb is always set as the startup object, but that's not even the window that loads up when the flag is false, it always comes after the splash screen.
I've search all through the code for any reference to creating a new instance of the login window to display it but can't find it. I've searched for where it checks what the flag is set to, but anything I've found for that is not in reference to loading the login window.
Any ideas?
What is the name of the login window class? You could either do a search in the entire solution to find all occurences of that name (e.g. by pressing Ctrl+Shift+F) or place the cursor on the class name and press Shift+F12. The latter will find all references of the login window class. In the search result window now look for new MyLoginWindow to see where it is instantiated.
From that location on you can use the same method again to find the callees and possibly the place in the code where the config flag is checked (Or you could place a breakpoint, debug and walk up the call stack to see where you are coming from - that could be easier).