How to access electron app's current browserWindow? - google-chrome-devtools

I'm stuck on a particular point with my Electron app:
When I open the devTools, I call mainWindow.webContents.openDevTools() from the app's menu. It's working fine on mainWindow.
The problem appears on child windows, opened by window.open(): the app menu is still working on every window, but it always call mainWindow's devtools (which is normal, since I told it to do so), where I would like to get current window's ones.
So I wonder if there is a way to call something like currentWindow.webContents.openDevTools() ? I found nothing in the documentation nor on SO nor by googling, so I guess I might haev missed something.
Let me precise a few things:
I'm still a newbie with Electron
I have no control on the pages that are called in the app, I'm trying to use electron as a kind of "restricted browser" to ship with a PHP-based application

After a bit more reading, I just found out that BrowserWindow.getFocusedWindow() is exactly what I was looking for.
So in my app menu, I juste call BrowserWindow.getFocusedWindow().webContents.openDevTools(), and it works as I expected.

Related

How to close a browser window after an exit event trigger in a unity webgl game (for accessibility sake)?

I have to develop a browser based game with WebGL (for cross-platform support) using Unity that allows people with severe disabilities to take full control of their experience. This also includes opening and closing the application on their own. Opening the browser and game is pretty straightforward since these people can simply open them using a program provided by another company (like Tobii), but now I am facing an issue when trying to close the window again, since there doesn't seem to be a way to achieve this from within the browser/game.
My question is, is there a way to close the browser with JavaScript or maybe even in Unity itself? Or should I look towards creating an application outside of the browser with something like Java (for cross-platform support) that manages the browser window?
I already looked into ways of doing it via JavaScript or even from within unity, but I simply couldn't find a solution. I tried using JavaScript's windows.close() function, but that only works on windows opened from within JavaScript itself by the looks of it. Looking at a stand-alone application then leaves the question of how to detect an exit request from the user when they are done playing the game.
What I am looking for is a way for them to select an 'exit' button within the game which then closes the browser, so they can return to their assistance program, without the help from another person.
Currently, the user is only able to make use of a single button and can't control mouse or cursor themselves, meaning that they can't close the browser on their own.
tl;dr how can I close a browser window using an exit button in a WebGL Unity game for a person who isn't able to themselves due to a handicap?
Pretty sure you can't
And that goes back to window.close only working on windows opened with JS. Originally it could close any window, but people started abusing that fact (think about things like the self-retweeting tweet, except it also closes your browser tab!)
So the restriction got added.
This is why we can't have nice things.

Black windows issue

I develop a web browser based on gtk+ and webkit2gtk in Rust and sometimes, all GTK+ windows become black.
Even the gtk inspector window that we get with the environment variable GTK_DEBUG=interactive is black.
Even thought the windows are black, the UI is still responsive since I can navigate the web with the keyboard (I see the window title updating, showing the new page URL and load progress).
Here are two actions that triggers this issue everytime they happen:
Destroying the web view
When running the application a second time, it sends a message via Unix Domain Socket to the first process so that it creates a new web view.
I have unfortunately no small example to reproduce the issue. If you want, I can show you the code of the project, but it is big, non-trivial and uses many abstraction layers over gtk+.
I know I don't give you a lot to help me, but if you can give me some explanations about how the rendering works and how to debug that, it would be very appreciated.
Can you give me some hints on how to debug this issue?
Is there a global OpenGL (or whatever) context for the GTK+ windows?
Are there some debuging tools to help me? (Setting G_MESSAGES_DEBUG=all does not show anything relevant.)
With strace, I was able to debug this issue:
I found out the FD used for IPC communication was still polled after being closed, so it was returning POLLNVAL.
Removing the FD with g_source_remove_unix_fd() fixed this issue.

Executing Capybara commands on debug while using Capybara Webkit?

With Pry (but also with Rubymine), I'm trying to debug a certain point in the code (using binding.pry). After calling Capybara's save_screenshot, I'm unable to execute any Capybara related commands (all commands die on time-out). This works out of a "debug mode" and in other web-drivers like Poltergeist.
I took a couple of hours today trying to debug it. I think I found the problem - or at least a way around it.
Our web site has a couple of links that open content in another browser window. Since the automation is quite ancient, and in that time Selenium didn't have a decent way to switch window-context, what we do is to visit the opened page by URL, and by this keep only a single window open at any given time.
This works, but something strange happens when running this test on "debug mode" (using binding.pry for example). Right before we do any actions on that specific page, we take a screen-shot using Capybara's save_screenshot method. On debug this results a corrupted image, and any following Capybara methods will fail on time-out. Opening this page using the link, and handling the windows context switching with Capybara's handle_window method solves the issue. It's still a mystery why it only happens with Capybara wekit though (as other web-drivers work properly). I'm guessing that perhaps the DOM might be structured differently.

Waiting mouse cursor in my GWT application stays infinitely (only in Chrome, only in Production)

Could you please tell me why I have waiting mouse cursor in my gwt application as if page not fully loaded ? It doesn't happen on dev server. It only happens in production. Also it's happening in Chrome but doesn't in IE.
Link to my app is here.
Screenshot
I checked it again in Chrome, but for me no wait cursor is Displayed. But i think, your Google Chrome is trying to open the Google Translate Menu. For me it came quickly and the page loading stopped and the mouse was at normal position.
I prefer you try updating your chrome.
I have also checked the same in my co-workers Laptop and its working fine too.
If problem still persists, please use CCleaner Software and clear all Temporary files, Browser Cache, Recent files etc. Why because, GWT creates a lot of temporary files which may reduce your system performance. So after each cleaning, just restart the system also. I had few such resolutions recently.
I opened your link in Firefox and got the following error
ERROR: Possible problem with your *.gwt.xml module file. The compile
time user.agent value (safari) does not match the runtime user.agent
value (gecko1_8). Expect more errors
This is because, you have compiled your code for Webkit browsers only. If you have added a line as below in your gwt module xml file,
<define-property name="user.agent" values="ie6">
you may either remove it or you can add more browser support via this.

Using NPAPI to detect browser minimize

Is there a way to use NPAPI to determine whether the browser is minimized.
Not directly. Depending on which platform you want (you should really specify things like that) there might be a way.
For example, on windows you might be able to get the browser HWND (NPN_GetValue with NPNVnetscapeWindow) and then check the state of that window with windows API calls.
On mac you're going to have a harder time of it; you could possibly intuit from the clipping information passed into NPP_SetWindow, but that doesn't tell you if the browser is minimized or if the plugin (or even the tab) is just not visible. Again, you'd need to try to figure out a way to use system calls to find your way back to the real window, but on Mac that's going to be very non-trivial.
Linux I'm not sure; you get a GtkSocket if you use XEmbed (only thing Chromium supports) and I haven't a clue if you can use that to get back to where you'd need to be to check minimized state.
So the short answer is no; NPAPI doesn't provide anything like that. You'd just have to try to find something that it does provide that gives you enough info to hack it.
Since I was using Core animation layer. I put in a timer which checks how often the candraw call back is called. If the time difference between the two callbacks are greater than a second I assume that either my plug-in is minimized or hidden.