Skip to content

Commit

Permalink
fix EvaluateJS (TLabAltoh/TLabWebViewVR#35)
Browse files Browse the repository at this point in the history
TLabAltoh committed Jan 4, 2025
1 parent 7f39622 commit 8b7ef49
Showing 8 changed files with 584 additions and 0 deletions.
Binary file modified Plugins/Android/libTLabWebView-release.aar
Binary file not shown.
422 changes: 422 additions & 0 deletions Resources/TLab/WebView/Samples/Browser Sample.prefab

Large diffs are not rendered by default.

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);
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Runtime/Sample/JSSnippets.cs
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);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Sample/JSSnippets.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Runtime/Test/BrowserAPITest.cs
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ public class BrowserAPITest : MonoBehaviour

[SerializeField] private GameObject m_prefab;

public void LoadUrl(string url) => m_container.browser.LoadUrl(url);

public void ScrollTo() => m_container.browser.ScrollTo(0, 50);

public void ScrollBy() => m_container.browser.ScrollBy(0, 50);
101 changes: 101 additions & 0 deletions Samples/Scenes/Mobile Sample.unity
Original file line number Diff line number Diff line change
@@ -1019,6 +1019,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_prefab: {fileID: 3182255551955723212, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
m_anchor: {fileID: 0}
--- !u!1 &1702036735
GameObject:
m_ObjectHideFlags: 0
@@ -1996,6 +1997,30 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.x
value: 251
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.y
value: 44
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.x
value: 125.5
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.y
value: -32
objectReference: {fileID: 0}
- target: {fileID: 3182255550635536445, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 0
@@ -2304,6 +2329,30 @@ PrefabInstance:
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4681490259713570090, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4681490259713570090, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4681490259713570090, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4681490259713570090, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4681490259713570090, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4681490259713570090, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4784752778758650270, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.x
value: 0
@@ -2576,6 +2625,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6387182006385117136, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_StringArgument
value: https://music.youtube.com/watch?v=DiTd771WumE&list=RDAMVMDiTd771WumE
objectReference: {fileID: 0}
- target: {fileID: 6469647243808811906, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 0
@@ -2588,6 +2641,30 @@ PrefabInstance:
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.x
value: 251
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.y
value: 44
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.x
value: 386.5
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.y
value: -32
objectReference: {fileID: 0}
- target: {fileID: 6629513091902531475, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 0
@@ -3060,5 +3137,29 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9199729575969404133, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9199729575969404133, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9199729575969404133, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9199729575969404133, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9199729575969404133, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9199729575969404133, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}

0 comments on commit 8b7ef49

Please sign in to comment.