Skip to content

Change default web behaviors that don't make sense in the context of Electron #12631

Open

Description

@nornagon

There are a number of behaviors that Electron inherits from Chromium which don't make sense for the vast majority of Electron apps. For instance:

  • dragging a file into a window navigates to that file
  • pinch-zooming in a window zooms the UI
  • Cmd+Click opens links a new BrowserWindow

Electron apps that don't want these behaviors currently have to disable them explicitly, in an ad-hoc and error-prone way. Since these behaviors are undesirable for almost every Electron app, we should disable them by default.

This issue is a tracking issue for discussion about this general idea; separate issues will be created for specific changes that need to be made.

Activity

  1. deleted a comment from welcome on Apr 17, 2018
  2. sindresorhus commented on Apr 17, 2018

    @sindresorhus
    Contributor

    dragging a file into a window navigates to that file

    Pretty much every Electron app source I've seen manually disables this.

    pinch-zooming in a window zooms the UI

    I've been developing for Electron for a long time, but only recently noticed this behavior and found a way to disable it. I bet there are lots of apps with this in production without even knowing it (Even the Slack app!).

  3. timfish commented on Apr 17, 2018

    @timfish
    Contributor

    setVisualZoomLevelLimits disables pinch zooming. Most production Electron apps I've checked already do this.

    webContents.setVisualZoomLevelLimits(1, 1);
    

    setZoomFactor and setLayoutZoomLevelLimits disable zoom scaling which should probably be left enabled for accessibility reasons.

  4. brenca commented on Apr 17, 2018

    @brenca
    Contributor

    We could expose the API to set the ZoomMode of a WebContents, by default zoom is per-origin in chromium, but we already have the internal code to override that behavior (code was ported from chromium).
    0f4341d

  5. nornagon commented on Apr 17, 2018

    @nornagon
    ContributorAuthor

    Yep, there are ways to work around all these undesirable features. But IMO, the default should be the expected behavior (don't pinch-zoom, don't navigate on drag/drop, etc.) and apps that want those features should have to explicitly enable them.

    @timfish I agree that layout zoom (i.e. Cmd++) should remain enabled by default. Visual zoom mostly results in people accidentally doing it and not knowing what happened, though, leading to weird bug reports :)

  6. timfish commented on May 3, 2018

    @timfish
    Contributor

    How about BrowserWindow option acceptFirstMouse:

    acceptFirstMouse Boolean (optional) - Whether the web view accepts a single mouse-down event that simultaneously activates the window. Default is false.

    I think the default should be true.

  7. nornagon commented on May 3, 2018

    @nornagon
    ContributorAuthor

    Hmm, I'm not sure I agree—on macOS at least, clicking on most native apps when they're not focused brings the window to the front without causing a mouse-click on whatever it was you clicked on. Clicking a button in a background window requires two clicks. (Perhaps it's different on other OSes though? We could change the default to be OS-specific.)

  8. timfish commented on May 3, 2018

    @timfish
    Contributor

    ah yes you're right and it looks like acceptFirstMouse is a macOS only option.

    On Windows, Electron already accepts first mouse by default. 👍

  9. nornagon commented on May 29, 2018

    @nornagon
    ContributorAuthor

    Images (and perhaps other elements, like <a> tags?) should be non-draggable by default.

  10. nornagon commented on May 29, 2018

    @nornagon
    ContributorAuthor

    Possibly, text should be non-selectable by default? i.e. user-select: none.

  11. remmycat commented on Dec 14, 2018

    @remmycat

    I was digging through google and issues to find out how to enable pinch-zoom, and only got tons of results on how to disable it, suggesting it's enabled by default.
    I finally found this issue (which is still open!) and #12679, it would be nice to have this change documented somewhere more visible.
    (At least i couldn't find anything yet)

  12. nornagon commented on Dec 14, 2018

    @nornagon
    ContributorAuthor

    I agree, but I'm not sure where to add that documentation! Where were you expecting to find it? That's probably the best place to put it :)

  13. remmycat commented on Dec 15, 2018

    @remmycat

    Hm, i mostly looked at
    https://electronjs.org/docs/api/web-frame#webframesetvisualzoomlevellimitsminimumlevel-maximumlevel (this is where the defaults should be listed i think)

    and https://electronjs.org/docs/api/web-contents#contentssetvisualzoomlevellimitsminimumlevel-maximumlevel

    Is the latter still supported? so far i only had success using webFrame. If not, a reference to webFrame would be helpful too. Until I researched on this had no idea what the 'web-frame' renderer export is or why it exists, because there was no reference to it in webContents nor BrowserWindow docs (or anywhere else it seems. though the search is not that reliable). Even now i have no clue why we have webFrame and webContents.

  14. anaisbetts commented on Feb 14, 2019

    @anaisbetts
    Contributor

    I am extremely Into all of these things 💖

  15. gdavidkov commented on Nov 21, 2019

    @gdavidkov
    Contributor

    Hi,
    is zoom still per-origin?

  16. naruaway commented on Nov 29, 2021

    @naruaway

    In terms of the default behavior, shouldn't we provide different presets like "browser-like" (e.g. use electron as web site wrapper or use electron as hackable web browser) or "app-like" (e.g. only show bundled HTML/JS to build native app like UX)? Then using the former preset can keep the existing behavior like "Cmd+Click opens links a new BrowserWindow".

    I think just changing the default behavior would make it difficult/error-prone to create browser-like experience instead. Also it would be nice to keep Chrome's behavior where possible especially for newcomers with mental models like "electron is just a web browser with hackable API"

    In addition to that, the official electron doc on sandbox is mentioning

    Rendering untrusted content in Electron is still somewhat uncharted territory, though some apps are finding success (e.g. Beaker Browser).

    So I would assume we should not completely ignore "using electron as hackable web browser" use case, which is also currently I am personally experimenting with.

  17. added a commit that references this issue on Dec 14, 2023
  18. grantcv1 commented on Mar 27, 2025

    @grantcv1

    Seven years on and I'm trying to make a tutorial video on the mac for our app and this useless behavior keeps ruining my takes. There is no way out of it so I have to scrap the take, reset my app, and start again -- hoping it doesn't happen again. It's a totally useless feature from which there is no escape other than to restart the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions