[PR #559] Add WebContents insertCSS functionality #1211

Open
opened 2026-01-29 16:58:26 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/ElectronNET/Electron.NET/pull/559

State: closed
Merged: Yes


Electron has functionality to insert CSS into a webpage using webContents.insertCSS. This PR implements that functionality in Electron.NET.

In WebContents.cs, the method public void InsertCSS(bool isBrowserWindow, string path) is added, which emits a socket message, webContents-insertCSS, along with the WebContents ID, the path to the file to insert, and whether the WebContents belongs to a BrowserWindow (isBrowserWindow = true) or to a BrowserView (isBrowserWindow = false).

In webContents.ts, the message is received and locates the BrowserWindow or BrowserView that matches the ID (since BrowserViews' WebContents IDs are incremented by 1000 on the Electron.NET side but not on the Host side, the comparison here is done against the Host IDs + 1000), and calls the insertCSS on the BrowserWindow or BrowserView's WebContents.

**Original Pull Request:** https://github.com/ElectronNET/Electron.NET/pull/559 **State:** closed **Merged:** Yes --- Electron has functionality to [insert CSS](https://www.electronjs.org/docs/api/web-contents#contentsinsertcsscss-options) into a webpage using webContents.insertCSS. This PR implements that functionality in Electron.NET. In `WebContents.cs`, the method `public void InsertCSS(bool isBrowserWindow, string path)` is added, which emits a socket message, `webContents-insertCSS`, along with the `WebContents` ID, the path to the file to insert, and whether the WebContents belongs to a `BrowserWindow` (`isBrowserWindow` = `true`) or to a `BrowserView` (`isBrowserWindow` = `false`). In `webContents.ts`, the message is received and locates the `BrowserWindow` or `BrowserView` that matches the ID (since `BrowserView`s' `WebContents` IDs are incremented by 1000 on the Electron.NET side but not on the Host side, the comparison here is done against the Host IDs + 1000), and calls the insertCSS on the `BrowserWindow` or `BrowserView`'s `WebContents`.
claunia added the pull-request label 2026-01-29 16:58:26 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#1211