Notalib / nativescript-webview-ext

Nativescript plugin with extended WebView functionality
Apache License 2.0
76 stars 37 forks source link

nsWebViewBridge undefined, ns-bridge-ready event never fires #117

Open tskweres opened 3 years ago

tskweres commented 3 years ago

My HTML webview looks like this:

<!DOCTYPE html>
    <html>
    <script>
      window.addEventListener("ns-bridge-ready", function(e) {
            var nsWebViewBridge = e.detail || window.nsWebViewBridge;
            try {
                nsWebViewBridge.emit('loadWindow');
            } catch (err) {
                console.log(err);
            }
      });
    </script>
    <body>
      <h1>My First Heading</h1>
    </body>
    </html>

The event ns-bridge-ready never fires. If i change to DOMContentLoaded, it fires, but window.nsWebViewBridge is undefined

Nativescript 8+ package.json:

{
  "name": "Test",
  "main": "./src/main.ts",
  "displayName": "Test",
  "templateType": "App template",
  "version": "7.0.8",
  "description": "Test",
  "author": "hello@test.io",
  "license": "SEE LICENSE IN <your-license-filename>",
  "publishConfig": {
    "access": "public"
  },
  "keywords": [
  ],
  "repository": "<fill-your-repository-here>",
  "homepage": "https://github.com/NativeScript/nativescript-app-templates",
  "bugs": {
    "url": "https://github.com/NativeScript/NativeScript/issues"
  },
  "dependencies": {
    "@angular/animations": "~11.2.7",
    "@angular/cdk": "^11.2.8",
    "@angular/common": "~11.2.7",
    "@angular/compiler": "~11.2.7",
    "@angular/core": "~11.2.7",
    "@angular/forms": "~11.2.7",
    "@angular/localize": "~11.0.0",
    "@angular/platform-browser": "~11.2.7",
    "@angular/platform-browser-dynamic": "~11.2.7",
    "@angular/router": "~11.2.7",
    "@nativescript/angular": "~11.8.0",
    "@nativescript/core": "^8.0.0",
    "@nativescript/secure-storage": "^3.0.0",
    "@nativescript/theme": "~3.0.0",
    "@ng-bootstrap/ng-bootstrap": "^9.1.0",
    "@nota/nativescript-webview-ext": "^8.0.0",
    "@nstudio/nativescript-checkbox": "^2.0.4",
    "@nstudio/nativescript-loading-indicator": "^4.0.0",
    "@nstudio/nativescript-pulltorefresh": "^3.0.1",
    "@schematics/angular": "^9.1.0",
    "@triniwiz/nativescript-image-cache-it": "^7.0.5",
    "@triniwiz/nativescript-pager": "^13.0.1",
    "@types/mocha": "^8.2.2",
    "bootstrap": "^4.5.0",
    "email-validator": "^2.0.4",
    "ethers": "^5.1.4",
    "etherspot": "^1.2.4",
    "libphonenumber-js": "^1.9.13",
    "moment": "^2.29.1",
    "nativescript-contacts-lite": "^0.2.7",
    "nativescript-lottie": "^5.0.3",
    "nativescript-materialdropdownlist": "^1.0.15",
    "nativescript-statusbar": "^5.0.0",
    "nativescript-taptic-engine": "^2.1.0",
    "nativescript-ui-chart": "^8.0.2",
    "nativescript-ui-listview": "^9.1.0",
    "nativescript-websockets": "^1.5.6",
    "numeral": "^2.0.6",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^6.6.7",
    "util": "^0.12.3",
    "zone.js": "~0.11.1"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~11.2.7",
    "@nativescript/ios": "8.0.0",
    "@nativescript/schematics": "^11.0.0",
    "@nativescript/webpack": "~5.0.0-beta.0",
    "@ngtools/webpack": "~11.2.6",
    "node-sass": "^5.0.0",
    "prettier": "^2.2.1",
    "tslint": "^6.1.3",
    "typescript": "~4.0.0"
  },
  "private": "true",
  "readme": "NativeScript Application"
}
meightythree commented 2 years ago

Same issue. Any update on it?

m-abs commented 2 years ago

I've just published v8.0.1, I hope that fixes the issue.

I think it is a timing issue, so I tried to change how we emit the ns-bridge-ready.

I'm not sure why but in DOMContentLoaded window.nsWebViewBridge is always undefined, at least on Android's webview.

If you're still having this issue, I need to know if it just iOS or Android or both, which versions etc.

meightythree commented 2 years ago

@m-abs Thanks for the update! That was really quick!

BenasApulskis190 commented 9 months ago

I am facing the same issue but for me ios simulation works as expected but then i connect device bridge is not working like in this issue #138