Skip to content

[Feature Request]: Allow rounded corners on WebContentsView #42288

Closed

Description

@spikecodes

Preflight Checklist

Problem Description

The WebContentsView in Electron currently only supports rectangular corners. Allowing customizable rounded corners would enable more flexible, modern designs for Electron apps.

Proposed Solution

Add a new method to the WebContentsView to set the corner radius:

const { BaseWindow, WebContentsView } = require('electron')
const win = new BaseWindow({ width: 800, height: 400 })

const view1 = new WebContentsView()
win.contentView.addChildView(view1)
view1.webContents.loadURL('https://electronjs.org')
view1.setBounds({ x: 0, y: 0, width: 400, height: 400 })
view1.setRoundedCorners(20); // for 20px

Alternatives Considered

Add an option to WebContentsView constructor to set corner radius:

const view1 = new WebContentsView({ roundedCorners: 20 }); // for 20px

Additional Information

No response

Activity

  1. samuelmaddock commented on May 30, 2024

    @samuelmaddock
    Member

    Tagging a similar issue request, for the now deprecated BrowserView #33426

  2. liuyike98 commented on Jul 20, 2024

    @liuyike98

    @jkleinsc any version can preview this feature?

  3. samuelmaddock commented on Jul 30, 2024

    @samuelmaddock
    Member

    @liuyike98 this'll be available in electron v33. you can access it via electron-nightly for an early preview.

  4. liuyike98 commented on Oct 28, 2024

    @liuyike98

    @samuelmaddock webContentsView overflow the parent view which has border radius. Image

    app.whenReady().then(() => {
      const win = new BaseWindow();
      win.contentView.setBorderRadius(20);
      win.contentView.setBackgroundColor("red")
    
      const view1 = new WebContentsView();
      view1.setBackgroundColor("green");
      view1.setBounds({ x: 0, y: 0, height: 100, width: 100 });
      view1.webContents.loadFile("./index.html");
      
      win.contentView.addChildView(view1);
    })
    
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