tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
83.82k stars 2.52k forks source link

[bug] [Error] Unhandled Promise Rejection: Not allowed by the scope #7513

Open conanchen opened 1 year ago

conanchen commented 1 year ago

Describe the bug

[Error] Unhandled Promise Rejection: Not allowed by the scope (anonymous function) (user-script:8:546:35590) asyncFunctionResume (anonymous function) promiseReactionJobWithoutPromise promiseReactionJob

Reproduction

  1. invoke tauri command from the main index.html , works as expect

    window.document
        .getElementById("finance_yahoo_website")
        .addEventListener("click", () => {
          console.log("you just clicked [finance_yahoo_website]")
    
          window.__TAURI__.invoke("plugin:myplugin|open_link", { "url": "open from /examples/basic-app/dist/index.html" });
          window.__TAURI__.invoke("plugin:myplugin|create_window");  
        });
  2. inject js file into newly created webview by plugin_builder.js_init_script(include_str!("../dist/inject.min.js"), the newly created webview will load external page like http://finance.yahoo.com

  3. in the inject.min.js file invoke a tauri command

    // Wait for the window to load
    async function handleLoaded() {
    console.log("done created floatDiv when window.load and invoke(open_link) for url", window.location.href)
    await invoke("plugin:myplugin|open_link", { "url": "open from /plugins/myplugin/js/inject.ts" });
    };
  4. from dev-tools console found error

    [Error] Unhandled Promise Rejection: Not allowed by the scope
    (anonymous function) (user-script:8:546:35590)
    asyncFunctionResume
    (anonymous function)
    promiseReactionJobWithoutPromise
    promiseReactionJob
  5. tauri.config.json

    "allowlist": {
      "all": true
    },
    "security": {
      "csp": null,
      "dangerousRemoteDomainIpcAccess": [
        {
          "domain": "finance.yahoo.com",
          "windows": [
            "finance_yahoo",
            "fundf10"
          ],
          "enableTauriAPI": true
        },
      ]
    }

Expected behavior

No response

Platform and versions

❯ cargo tauri info
WARNING: Only one package manager should be used, but found pnpm and yarn.
         Please remove unused package manager lock files, will use pnpm for now!

[✔] Environment
    - OS: Mac OS 12.6.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.73.0-nightly (1065d876c 2023-07-09)
    ✔ Cargo: 1.73.0-nightly (45782b6b8 2023-07-05)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: nightly-x86_64-apple-darwin (environment override by RUSTUP_TOOLCHAIN)
    - node: 16.17.0
    - pnpm: 7.29.1
    - yarn: 1.22.19
    - npm: 8.15.0

[-] Packages
    - tauri [RUST]: 1.4.1
    - tauri-build [RUST]: 1.4.0
    - wry [RUST]: 0.24.3
    - tao [RUST]: 0.16.2
    - @tauri-apps/api [NPM]: 1.4.0
    - @tauri-apps/cli [NPM]: 1.4.0

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: ../dist
    - bundler: Rollup

Stack trace

No response

Additional context

No response

Xutaotaotao commented 5 months ago

I have the same bug, how to solve it

Xutaotaotao commented 5 months ago

https://github.com/tauri-apps/tauri/issues/9849

GuoHuiChen commented 2 months ago

I have save problem。 window.TAURI.invoke("plugin:clipboard|has_text")