question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Keyboard shortcuts in webview applications

See original GitHub issue

Hello,

we are migrating to NWjs v0.30.x . We have noticed difference from 0.27.x in keyboard events in combination with webview.

We have keyboard shortcuts in our application that were relying on keydown event, like

window.addEventListener("keydown", (evt) => {
    if (evt.ctrlKey) {
        switch (evt.key) {
            case "q": return nw.App.quit();
            case "n": return nw.Window.create(location.href);
            // etc...
        }
    }
});

But this has stopped to work, because the parent frame doesn’t receive the keydown event when webview is focused.

(IM)POSSIBLE WORKAROUNDS

  • nw.Window.get().menu = new nw.Menu() ... - but we have undecorated window and thus this is unusable on Windows and Linux
    • We would require to be able to hide visual representation of the menu (maybe the Alt key to show it)
  • nw.Shortcut - but it is system-wide and unregistereing them based on focus is somewhat unreliable
    • We would require to be able to register shortcut just for the application, not system-wide
  • chrome.commands - the shortcut must start with a special key (like Ctrl, Alt, …), so shortcuts like F5 for reloading the webview are impossible
    • We would require to be able to register shortcut with any key combination, including a single key like Esc, F5, …

Any suggestions?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cipriancraciuncommented, Apr 26, 2019

As others have mentioned this issue is critical for those implementing anything touching webview elements…

And unfortunately the proposed workaround of injecting JS into the webview and using messages is not quite “safe”, especially since webview elements are used to contain untrusted sources…

(Moreover given that for many releases this feature worked, and now it suddenly doesn’t isn’t very reassuring for the reliability and stability of the platform…)


Is there some documentation on how to use at least the chrome.commands feature in nw.js?

0reactions
ghostcommented, Aug 13, 2019

Can anyone just guide me (just in short): i have a concept which could be build using nw.js. I have worked longer time ago with electron.

I want to have a parent window, which embeds a webview just as a child, to view it like a movie. The webview should be safe, but it’s just like a gimmick. The parent - the master - the worker - that’s the parent, so every shortcut must be handled by the parent, not the webview.

What’s the way right now?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Screen reader keyboard shortcuts for mobile apps on Windows
Keyboard shortcuts ; Navigate to the previous character. Alt + Shift + Left arrow ; Select the focused element. Alt + Enter ;...
Read more >
Manage shortcuts | Android Developers
Your app tracks usage for dynamic shortcuts by calling the pushDynamicShortcut() method and passing it the ID of the shortcut when a relevant ......
Read more >
Listen Webview Key Events from software keyboard in ...
Is it possible to handle software keyboard events from a webview in a host Android application? For example, can my application's Activity ...
Read more >
WebView2: Forwarding Alt Keys to a Host WPF Window
With focus in the WebView, if you now press the alt key at that or any alt key combination, you'll find out that...
Read more >
Windows Subsystem for Android Keyboard Shortcuts for ...
Keyboard Shortcuts for in-app Navigation ; Navigate to the item below, Alt + Down arrow ; Navigate to the first item, Alt +...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found