mirror of
https://github.com/scratchfoundation/scratch-desktop.git
synced 2024-12-22 21:52:31 -05:00
Add last-resort hook to stop link navigation
Links which cause the browser to navigate to another page should be removed or disabled in Scratch Desktop to prevent Electron from navigating away from the editor. If we miss disabling or removing such a link, this last-resort hook will disable navigation after the user clicks a link.
This commit is contained in:
parent
6bf5d4a41a
commit
c8f6b38df2
1 changed files with 16 additions and 0 deletions
|
@ -8,6 +8,22 @@ import styles from './app.css';
|
|||
|
||||
const defaultProjectId = 0;
|
||||
|
||||
const captureClick = function (ev) {
|
||||
for (const element of ev.path) {
|
||||
if (element.href) {
|
||||
// prevent clicking links
|
||||
// this is a last-resort test: if we get here that means there's work to do in the GUI
|
||||
console.warn(`Suppressing click on link to ${element.href}`);
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.addEventListener('click', captureClick, true);
|
||||
});
|
||||
|
||||
// Register "base" page view
|
||||
// analytics.pageview('/');
|
||||
|
||||
|
|
Loading…
Reference in a new issue