2017-10-13 10 views
0

NW.jsとwebviewを使用して外部のウェブサイトを制御したいが、いつでもこれを試してみるとエラーがある - 角度は定義されていない。 NW.js - webview - 角度が定義されていないエラー

マイソース:

index.htmlを

html...head...body... 
<webview id="webview" name="webview" src="https://google.com/" allownw></webview> 
<script src="../js/script.js"></script> 
...body...html 

script.js

(function() { 
var gui = require('nw.gui'); 
var win = gui.Window.get(); 
var webview = document.getElementById("webview"); 

var tray = new gui.Tray({ 
    icon : 'assets/icon.png' 
}); 

var menu = new gui.Menu(); 

menu.append(new gui.MenuItem({ 
    type: 'normal', 
    label: '▶️ Play', 
    click: function() { 
     webview.executeScript({code:"var player=angular.element(document.body).injector().get('player'); player.play();"}); 
    } 
})); 
tray.menu = menu; 

}()); 

私のためにこのコードプロデュースエラー:にReferenceError:角度を

注定義されていません。ウェブサイトgoogle.comはほんの一例です。 nw.jsdocsから

答えて

0

loading local files in webview

Add the following permission to the manifest:

"webview": { 
    "partitions": [ 
     { 
      "name": "trusted", 
      "accessible_resources": [ "<all_urls>" ] 
     } 
    ] 
    } 

and add 'partition="trusted"' attribute to the webview tag.

これは<scriptタグはあなたの../js/script.jsファイルにアクセスすることはできません理由の一つです。私はまた、あなたのローカルファイルの例への非相対パスを使用することをお勧めします:chrome-extension://yourdomain/js/script.js(そして、それはディレクトリではなくルートに相対的です)。

Googleのdocsから、accessible_resourcesを特定のパターンまたはファイルに設定できます。

insertCss,,イベント、特にexecuteScriptがGoogleのドキュメントに記載されています。

注:それはあなたのプログラムがアクセス権を持っているにアクセスすることができますので、あなたがあなたのnwjsコンテキスト(allownw)へのWebViewのアクセス権を与えたくないかもしれません。これは、外部URLとhttpの両方の場合に特に当てはまります。MITM改ざんや第三者の変更により、アプリケーションが実行されているPCへの昇格アクセスをユーザーに与える可能性があります。

あなたの例では、私はscript.jsをwebviewの外に保ち、スクリプトインジェクションを介してWebviewを計測します。

関連する問題