Skip to content

Commit

Permalink
add OnPageStart (TLabAltoh/TLabWebViewVR#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
TLabAltoh committed Jan 8, 2025
1 parent 6ad0d6d commit 3c919b3
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 40 deletions.
Binary file modified Plugins/Android/libTLabWebView-release.aar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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);
};

This file was deleted.

3 changes: 3 additions & 0 deletions Runtime/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ public void DispatchMessageQueue()
var message = new EventCallback.Message(@object);
switch ((EventCallback.Type)message.type)
{
case EventCallback.Type.OnPageStart:
m_eventCallback.onPageStart.Invoke(message.payload);
break;
case EventCallback.Type.OnPageFinish:
m_eventCallback.onPageFinish.Invoke(message.payload);
break;
Expand Down
2 changes: 2 additions & 0 deletions Runtime/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public class EventCallback
public enum Type
{
Raw,
OnPageStart,
OnPageFinish,
OnDownload,
OnDownloadStart,
Expand All @@ -159,6 +160,7 @@ public Message(string json) : base(json) { }
public string payload;
}

public UnityEvent<string> onPageStart;
public UnityEvent<string> onPageFinish;
public UnityEvent<Download.Request> onDownload;
public UnityEvent<Download.EventInfo> onDownloadError;
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Sample/JSSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public class JSSnippets : MonoBehaviour
{
[SerializeField] private BrowserContainer m_container;

public void RemoveEventFromBeforeUnload()
public void DisableBeforeUnload()
{
var js = Resources.Load<TextAsset>("TLab/WebView/Samples/Scripts/JS/remove-event-from-beforunload")?.ToString();
var js = Resources.Load<TextAsset>("TLab/WebView/Samples/Scripts/JS/disable-beforunload")?.ToString();
m_container.browser.EvaluateJS(js);
}
}
Expand Down
28 changes: 16 additions & 12 deletions Samples/Scenes/Mobile Sample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1999,27 +1999,27 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.x
value: 251
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.y
value: 44
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.x
value: 125.5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3168540923415432720, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.y
value: -32
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3182255550635536445, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
Expand Down Expand Up @@ -2517,6 +2517,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5712475638812610771, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5790450369921081937, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 0
Expand Down Expand Up @@ -2639,27 +2643,27 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.x
value: 251
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_SizeDelta.y
value: 44
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.x
value: 386.5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6573493046413690567, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchoredPosition.y
value: -32
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6629513091902531475, guid: 4272bd6725bd64846b07be9b4d76ad90, type: 3}
propertyPath: m_AnchorMax.y
Expand Down

0 comments on commit 3c919b3

Please sign in to comment.