2016-04-07 8 views
0

これは初めてfirefoxアドオンをビルドするのを初めて知りました。開いているすべてのタブをウィンドウに保存したいのですが、そのためにはsdk/tabsが必要です。私はタブ=は( "SDK /タブ")の行を必要とVARに達すると、私は参照エラーを取得FireFox webextensionでsdk/tabsを使用しているときのReferenceError

/* 
Given the name of a beast, get the URL to the corresponding image. 
*/ 
debugger; 
var tabs = require("sdk/tabs"); 
function beastNameToURL(beastName) { 
    switch (beastName) { 
    case "Save Session": 
     debugger; 
     for (let tab of tabs) 
      console.log(tab.url); 
     return; 
    case "Load Session": 
    debugger; 
     return chrome.extension.getURL("beasts/snake.jpg"); 
    case "Turtle": 
     return chrome.extension.getURL("beasts/turtle.jpg"); 
    } 
} 

/* 
Listen for clicks in the popup. 

If the click is not on one of the beasts, return early. 

Otherwise, the text content of the node is the name of the beast we want. 

Inject the "beastify.js" content script in the active tab. 

Then get the active tab and send "beastify.js" a message 
containing the URL to the chosen beast's image. 
*/ 
document.addEventListener("click", function(e) { 

    if (!e.target.classList.contains("btn")) { 
    return; 
    } 


    var chosenBeast = e.target.textContent; 
    var chosenBeastURL = beastNameToURL(chosenBeast); 

    chrome.tabs.executeScript(null, { 
    file: "/content_scripts/beastify.js" 
    }); 

    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { 
    chrome.tabs.sendMessage(tabs[0].id, {beastURL: chosenBeastURL}); 
    }); 

}); 

は、ここに私のjsファイルです。 Error snapshot

のGithub:https://github.com/sagar-shah/Session-manifest

親切に私はどのように私はこのエラーを解決します知っています。私が完全に失われているアドオンでこれは私の初めてのことです。

ありがとうございます。

更新: jsファイルでグローバルに宣言しようとしました。今私はタブの未定義のエラーを取得しています。

Update2: @matagusが指摘しているように、sdkとwebextensionsを使って開発をミックスしていました。私はwebextensionsを使って開発に行くことにしました。新しいリポジトリへのリンクが更新されました。

+0

「main」ですか?「manifest.json」、「correct?すべての私のアドオンで 'index.js'に設定されています –

+0

@FastSnailわかりません。チュートリアルではメインファイルはindex.jsで与えられていますが、ボタンをクリックするとポップアップを開き、ボタンをクリックするとjsファイルは実行しません。マニフェストにはポップアップファイルの詳細が含まれているので、私はmanifest.jsonをmainとして追加すると考えました。 – Posiedon

+0

私は昨日それをうまく使った。それをグローバルに宣言しよう - https://github.com/Noitidart/jpmOAuth/blob/master/index.js - あなたは 'jpm run'または' jpm xpi'を使っていますか?あなたは 'cfx'の権利をしていないという意味ですか? 'cfx'は廃止されました。 – Noitidart

答えて

4

エラーはpackage.jsonにあります。アドオンのメインファイルがmanage.jsonであることをアドオンSDKに伝えています。 [ドキュメント]によるとメインの値は、次のようになります。

A string representing the name of a program module that is located in one of the top-level module directories specified by lib. Defaults to "index.js". 

ですから、index.jsにその値を変更する必要があります。

さらに、Firefox addon built using the addon-sdk( 'manifest.json'とjpmツールを使用して作成したもの)と、マニフェストを書く必要がある新しいWebExtensionsの違いが見当たらないと思います。すでに持っているのと同じようにjson '。

UPDATE:再び

:あなたはWebExtensionsとSDKベースのアドオンとの違いを逃しています。今度はWebExtensionを作成しましたが、SDKを使用しようとしています。それは不可能です。 sdk(var tabs = require("sdk/tabs");)からインポートする代わりに、chrome.tabsを直接使用してください。

+0

2つの違いを指摘してくれてありがとう。新しいリポジトリを作成しましたが、まだエラーが発生しています。助けてください。 – Posiedon

+0

私は自分の答えを更新しました、それをチェックしてください。 – matagus

関連する問題