fix: context-menu event emitted in draggable regions (#45841)

* fix: context-menu event emitted in draggable regions

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* fix: only trigger on mouse release

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-02-27 16:07:54 -06:00 committed by GitHub
parent 260933601e
commit b6d61577aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 3 deletions

View file

@ -2861,18 +2861,18 @@ describe('webContents module', () => {
await once(w.webContents, 'context-menu');
await setTimeout(100);
expect(contextMenuEmitCount).to.equal(1);
});
it('emits when right-clicked in page in a draggable region', async () => {
ifit(process.platform !== 'win32')('emits when right-clicked in page in a draggable region', async () => {
const w = new BrowserWindow({ show: false });
await w.loadFile(path.join(fixturesPath, 'pages', 'draggable-page.html'));
const promise = once(w.webContents, 'context-menu') as Promise<[any, Electron.ContextMenuParams]>;
// Simulate right-click to create context-menu event.
const opts = { x: 0, y: 0, button: 'right' as const };
const midPoint = w.getBounds().width / 2;
const opts = { x: midPoint, y: midPoint, button: 'right' as const };
w.webContents.sendInputEvent({ ...opts, type: 'mouseDown' });
w.webContents.sendInputEvent({ ...opts, type: 'mouseUp' });