Skip to content

[pyinstaller] Cannot read properties of undefined (reading 'api') #1504

Closed
@Liripo

Description

@Liripo

Specification

  • pywebview version: 5.3
  • operating system: windows
  • web renderer: default

Description

The js api works when I run it directly from source, but it doesn't work after compiling with pyinstaller.

example code:

import webview
from pathlib import Path
class Api:
    def add(self,a,b):
        return a+b


webview.create_window('Hello world', url= str(Path('web/index.html').absolute()),js_api=Api())
webview.start(http_server=True,debug=True)

web/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First App</title>
</head>
<body>
  <h1>JS to Python</h1>
  <main>
      <button onclick="onClickOk()">OK</button>
  </main>
  
  <script>
      async function onClickOk(){
          let res = await window.pywebview.api.add(10, 15);
          console.log(res);
      }
  </script>
</body>
</html>

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions