WebPlatformForEmbedded / WPEWebKit

WPE WebKit port (downstream)
210 stars 135 forks source link

[wpe-2.38] Black screen on FIIT app login with password page #1351

Closed pradeep-raveendranpillai-infosys closed 1 week ago

pradeep-raveendranpillai-infosys commented 2 weeks ago

After launching FiiT app - https://widgets.metrological.com/lightning/liberty/2e3c4fc22f0d35e3eb7fdb47eb7d4658#app:tv.fiit.app on WPE-2.38 based build, go to home page and click "Log In" button. In the next page, click on "Login with Password" button. A black screen is shown, instead of displaying next page. On WPE 2.22 build, this issue is not seen.

From the logs the below error is seen:

wpe.sh[4781]: [Wed, 19 Jun 2024 09:04:59]:[main.cpp:200]:[consoleMessageSentCallback]:[Warning]: consoleMessageSentCallback-> https://big-fiit-virgin.core-prod.fiit-tech.net/vendors/dd13cff3ebe7a98ce659.js:2 messageString: TypeError: undefined is not an object (evaluating 'window.webkit.messageHandlers.auxiliaryWindowLocation.postMessage')

Using webinspector it is found that the below code snippet of the FiiT app is where the error is thrown:

const sendWebkitMessage = ({ blankScreen }: SendWebkitMessageArgs = {}) => { if (!window.webkit?.messageHandlers) { return; } if (blankScreen) { window.webkit.messageHandlers.auxiliaryWindowLocation.postMessage(''); } else { window.webkit.messageHandlers.auxiliaryWindowLocation.postMessage(window.location.href); } };

It is understood that in WPE 2.38 build, window.webkit.messageHandlers is defined so it tries to use the method postMessage and fails to do so, while in WPE 2.22 webkit object is undefined so browser returns from the method without problems. In desktop Safari version 17.5 also, the object webkit is undefined.

The webkit object as understood from documentation, meant to exist only in a WkWebView environment which is when WebKit browser is executed from another native application on iOS/macOS. And the purpose is to have a communication between native app and the browser. Would like to know if the above understanding of window.webkit object/interface is correct. Also wanted to know if it's intended to enable this feature for WPE by default.

I disabled the same by adding -DENABLE_USER_MESSAGE_HANDLERS=OFF in my webkit recipe file via PACKAGECONFIG option. With this, the issue is not seen.

pgorszkowski-igalia commented 2 weeks ago

@pradeep-raveendranpillai-infosys : I see in the WPE 2.22 code that it is also enabled by default there: https://github.com/WebPlatformForEmbedded/WPEWebKit/blob/wpe-2.22/Source/cmake/WebKitFeatures.cmake#L185, so maybe you disabled it in your repository?

pradeep-raveendranpillai-infosys commented 2 weeks ago

I see that its not disabled in wpe 2.22 as well, even in my meta-layers as well. Strange!

By the way may I know what is the purpose of USER_MESSAGE_HANDLERS?

pgorszkowski-igalia commented 2 weeks ago

It allows exposing DOM JS API that can pass serializable JS objects to native code in the uiprocess and receive replies back.

https://wpewebkit.org/reference/stable/wpe-webkit-1.1/method.UserContentManager.register_script_message_handler.html

https://wpewebkit.org/blog/06-integrating-wpe.html#user-script-messages

pradeep-raveendranpillai-infosys commented 2 weeks ago

Using web-inspector I found that window.webkit is undefined in the case of wpe 2.22 build. I found that in wpe 2.38, in the file WebKitNamespace.idl file, "Exposed=Window" is defined as given below. [ Conditional=USER_MESSAGE_HANDLERS, Exposed=Window ] interface WebKitNamespace { readonly attribute UserMessageHandlersNamespace messageHandlers; };

While for 2.22 that is not present. Is this the reason why window.webkit is undefined in 2.22 even-though USER_MESSAGE_HANDLERS is enabled?

pgorszkowski-igalia commented 1 week ago

The reason why it is not defined in WPE 2.22 is that you don't register any script message handler by webkit_user_content_manager_register_script_message_handler. If there is no registered any script message handler then window.webkit API is disabled.

In 2.38 you register "wpeNotifyWPEFramework": webkit_user_content_manager_register_script_message_handler(userContentManager, "wpeNotifyWPEFramework"); https://github.com/LibertyGlobal/rdkservices/blob/lgi-thunder4.2-20230922/WebKitBrowser/WebKitImplementation.cpp#L3682

pradeep-raveendranpillai-infosys commented 1 week ago

I see. Thank you.

pgorszkowski-igalia commented 1 week ago

@pradeep-raveendranpillai-infosys : I closed this ticket, but if you have more questions, don't hesitate to reopen it.