Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running Linux AppImage containing Webkit #1029

Closed
freakboy3742 opened this issue Jan 3, 2023 · 8 comments
Closed

Error running Linux AppImage containing Webkit #1029

freakboy3742 opened this issue Jan 3, 2023 · 8 comments
Labels
bug A crash or error in behavior. linux The issue relates Linux support.

Comments

@freakboy3742
Copy link
Member

Describe the bug

If you package a GTK app that references Webkit, the app will build, but will fail at runtime.

Steps to reproduce

  1. Obtain a copy of Toga Tutorial 3
  2. Add the default Toga Appimage configuration to pyproject.toml:
[tool.briefcase.app.tutorial.linux.appimage]
system_requires = [
    'gir1.2-webkit-3.0',
    'libcairo2-dev',
    'libgirepository1.0-dev',
    'libgtk-3-dev',
    'libpango1.0-dev',
    'librsvg2-dev',
    'libwebkitgtk-3.0-0',
]
linuxdeploy_plugins = [
    'DEPLOY_GTK_VERSION=3 gtk',
]
  1. Package app as an AppImage
  2. Run AppImage on any platform other than Ubuntu 18.04
  3. See runtime error:
           ** (__main__.py:548313): WARNING **: 09:22:13.888: Failed to load shared library 'libwebkit2gtk-4.0.so.37' referenced by the typelib:                   subprocess.py:644
           /lib/x86_64-linux-gnu/libsecret-1.so.0: undefined symbol: g_task_set_name                                                                                                
           /tmp/.mount_Tutori7Nvvex/usr/app_packages/toga_gtk/widgets/webview.py:19: Warning: cannot retrieve class for invalid (unclassed) type 'void'            subprocess.py:644
             self.native = WebKit2.WebView()                                                                                                                       subprocess.py:644
           Traceback (most recent call last):                                                                                                                      subprocess.py:644
             File "/tmp/.mount_Tutori7Nvvex/usr/app_packages/toga_gtk/app.py", line 105, in gtk_startup                                                            subprocess.py:644
               self.interface.startup()                                                                                                                            subprocess.py:644
             File "/tmp/.mount_Tutori7Nvvex/usr/app/tutorial/app.py", line 9, in startup                                                                           subprocess.py:644
               self.webview = toga.WebView(                                                                                                                        subprocess.py:644
             File "/tmp/.mount_Tutori7Nvvex/usr/app_packages/toga/widgets/webview.py", line 51, in __init__                                                        subprocess.py:644
               self._impl = self.factory.WebView(interface=self)                                                                                                   subprocess.py:644
             File "/tmp/.mount_Tutori7Nvvex/usr/app_packages/toga_gtk/widgets/base.py", line 13, in __init__                                                       subprocess.py:644
               self.create()                                                                                                                                       subprocess.py:644
             File "/tmp/.mount_Tutori7Nvvex/usr/app_packages/toga_gtk/widgets/webview.py", line 19, in create                                                      subprocess.py:644
               self.native = WebKit2.WebView()                                                                                                                     subprocess.py:644
           TypeError: could not get a reference to type class                        

Expected behavior

App should run without error, displaying the "graze" webkit browser on GTK.

Screenshots

No response

Environment

  • Operating System: Ubuntu 22.04, Arch
  • Python version: 3.10
  • Software versions:
    • Briefcase: 0.3.10.dev207
    • Toga: 0.3.0.dev39

Logs

Briefcase build:
briefcase.2023_01_03-09_19_06.build.log

Briefcase run:
briefcase.2023_01_03-09_22_29.run.log

Additional context

The app runs fine under Ubuntu 18.04.

The problem appears to be that the webkit libraries aren't being included in the AppImage. The Docker container installs libwebkit-3.0; but at runtime, GTK attempts to load libwebkit2-4.0. There's no reference to any Webkit library in the AppImage build logs.

The use of libwebkit-3.0 appears to be a hangover from the days when Briefcase used an Ubuntu 16.04 base; Ubuntu 18.04 provides both libwebkit-3.0 and libwebkit2-4.0. However, modifying the system_requires to use libwebkit2-4.0 (and the corresponding gir package) doesn't fix the problem; it changes the error to a problem with libjavascriptcoregtk-4.0.

@freakboy3742 freakboy3742 added bug A crash or error in behavior. up-for-grabs linux The issue relates Linux support. labels Jan 3, 2023
@freakboy3742
Copy link
Member Author

All signs point to this being a bug in linuxdeploy-gtk-plugin; This (rejected) PR contains a number of changes that might be worth exploring linuxdeploy/linuxdeploy-plugin-gtk#37

@freakboy3742
Copy link
Member Author

I've got an initial attempt at a patched linuxdeploy-plugin-gtk on this branch

So far, I've resolved the problems linking against libwebkit2; however, the app is now showing a runtime crash with the webkit content subprocess.

@freakboy3742
Copy link
Member Author

More details on the crash - it appears to be because webkit2 uses a subprocess to manage network and rendering activities.

This executable is included in the AppImage as <appimage>/usr/lib/x86_64-linux-gnu/webkit2gtk-4.0/WebkitNetworkProcess; but the running app attempts to launch the system version at /usr/lib/x86_64-linux-gnu/webkit2gtk-4.0/WebkitNetworkProcess.

This results in a SIGABRT. There is also a Received invalid message: 'NetworkProcess_CloseITPDatabase' on the console of the packaged app; it's not clear if this is a symptom of the crash, or part of the cause.

At the very least, there appears to be an internal reference to the network process binary that needs to be updated. I'm hitting the limits of my expertise at this point, so if anyone wants to tinker with the starting point I've provided, they're more than welcome to do so.

@freakboy3742
Copy link
Member Author

Looks like this issue might have some leads on additional fixes that are needed...

@freakboy3742
Copy link
Member Author

freakboy3742 commented Jan 4, 2023

Ok; that issue doesn't appear to do everything. It seems to suggest that a change something akin to:

# Manually patch libwebkit libraries to use internal references.
# This is needed because webkit uses external binaries with hard-coded paths.
if $(pkg-config "webkit2gtk-4.0" --exists); then
    echo "Manually patching hardcoded path references in Webkit binaries"
    find "$APPDIR"/usr/lib* -name 'libwebkit*' -exec sed -i -e "s|/usr|././|g" '{}' \;
fi

will fix the problem - but in my testing, that changes the error to an "unable to execute child process ././lib/x86_64-...". This makes sense to me, as the path is relative, and will be highly sensitive to the binary that invokes it.

@freakboy3742
Copy link
Member Author

I'm going to close this WONTFIX. It's an inherent problem with linuxdeploy, unrelated to how Briefcase is using it (See this bug report). If Linuxdeploy ever addresses this issue, and it turns out it requires a different invocation of linuxdeploy, then I'm happy to revisit this; but for now, there's literally nothing we can do to Briefcase that will fix this problem.

We've also introduced Linux System packages as the new packaging default for Linux, and those don't have this problem.

@freakboy3742 freakboy3742 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2023
@layday
Copy link

layday commented Apr 29, 2023

It's been a couple of years now and I don't remember the specifics, but I recall having gone down a similar path and having resorted to using proot to mount webkit2gtk under /usr/lib in the app image. These lines are probably of interest to anyone who might stumble on this issue.

@rmartin16
Copy link
Member

It's been a couple of years now and I don't remember the specifics, but I recall having gone down a similar path and having resorted to using proot to mount webkit2gtk under /usr/lib in the app image. These lines are probably of interest to anyone who might stumble on this issue.

permalink for posterity: https://github.com/layday/instawow/blob/0acca4a4f37e60fccc4cdc35c29eaf9565cac432/gui-webview/linuxdeploy-plugin-zzzinstawowwebkit2gtk.sh#L92-L105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior. linux The issue relates Linux support.
Projects
None yet
Development

No branches or pull requests

3 participants