-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix EvaluateJS (TLabAltoh/TLabWebViewVR#35)
Showing
8 changed files
with
584 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
Resources/TLab/WebView/Samples/Scripts/JS/remove-event-from-beforunload.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
window.onbeforeunload = null; | ||
|
||
const removeUnloadListeners = () => { | ||
const eventListeners = window.getEventListeners?.(window); | ||
if (eventListeners?.beforeunload) { | ||
eventListeners.beforeunload.forEach(listener => { | ||
window.removeEventListener('beforeunload', listener.listener); | ||
}); | ||
} | ||
}; | ||
|
||
removeUnloadListeners?.(); | ||
|
||
window.onbeforeunload = function() { | ||
console.log("Blocked a 'beforeunload' ..."); | ||
event.stopImmediatePropagation(); | ||
}; | ||
|
||
const originalAddEventListener = window.addEventListener; | ||
window.addEventListener = function (type, listener, options) { | ||
if (type === 'beforeunload') { | ||
console.warn("Blocked a 'beforeunload' listener from being added."); | ||
return; | ||
} | ||
originalAddEventListener.call(this, type, listener, options); | ||
}; |
7 changes: 7 additions & 0 deletions
7
Resources/TLab/WebView/Samples/Scripts/JS/remove-event-from-beforunload.txt.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using UnityEngine; | ||
|
||
namespace TLab.WebView.Sample | ||
{ | ||
public class JSSnippets : MonoBehaviour | ||
{ | ||
[SerializeField] private BrowserContainer m_container; | ||
|
||
public void RemoveEventFromBeforeUnload() | ||
{ | ||
var js = Resources.Load<TextAsset>("TLab/WebView/Samples/Scripts/JS/remove-event-from-beforunload")?.ToString(); | ||
m_container.browser.EvaluateJS(js); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters