BUGFIX: Prevent runtime NotAllowedError on Safari (#1507)

Could occur when the browser’s window is resized.
This commit is contained in:
robofinch 2024-07-20 03:16:02 -05:00 committed by GitHub
parent 4502fd443e
commit 42bcfa1889
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -94,7 +94,11 @@ export function Overview({ children, mode }: IProps): React.ReactElement {
triggerMouseEvent(node, "mousedown");
triggerMouseEvent(document, "mousemove");
triggerMouseEvent(node, "mouseup");
triggerMouseEvent(node, "click");
// According to a comment in the above GitHub issue, apparently mousemove is important,
// but click probably isn't. This click causes a runtime error in Safari (NotAllowedError),
// but not Chromium. If further errors occur, a more thorough fix, possibly using
// navigator.userActivation.isActive, might be necessary.
// triggerMouseEvent(node, "click");
}, 100),
[],
);
@ -111,8 +115,7 @@ export function Overview({ children, mode }: IProps): React.ReactElement {
}, [fakeDrag]);
const triggerMouseEvent = (node: HTMLDivElement | Document, eventType: string): void => {
const clickEvent = document.createEvent("MouseEvents");
clickEvent.initEvent(eventType, true, true);
const clickEvent = new MouseEvent(eventType, { bubbles: true, cancelable: true });
node.dispatchEvent(clickEvent);
};