Skip to content

Commit

Permalink
Merge pull request #3 from kynetiv/permission
Browse files Browse the repository at this point in the history
Add permission and prevent default event
  • Loading branch information
kynetiv authored Mar 14, 2022
2 parents 3947d2d + c8da90c commit ca1aac0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"author": "kynetiv",
"description": "Guards browser from navigation / refresh of the currently inspected page. Activate by visiting devtools 'Refresh Guard' panel tab.",
"devtools_page": "devtoolsRefreshGuard.html",
"permissions": [
"activeTab"
],
"icons": {
"16": "refresh-guard16.png",
"32": "refresh-guard32.png",
Expand Down
11 changes: 9 additions & 2 deletions refreshGuard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ chrome.devtools.panels.create(
panel.onShown.addListener(function(window){
let code = `
(function () {
window.onbeforeunload = function(){
return "Leave site?";
window.onbeforeunload = function(event){
var e = event || window.event;
// Cancel the event
e.preventDefault();
var confirmText = 'Leave site?';
if (e) {
e.returnValue = confirmText;
}
return confirmText;
}
})()`
chrome.devtools.inspectedWindow.eval(code)
Expand Down

0 comments on commit ca1aac0

Please sign in to comment.