2016-05-04 15 views
0

現在作業しているChrome拡張機能で問題が発生しています。その機能は、ポップアップテキストエリアからのユーザー入力を受け取り、改行で区切られた各URLのタブを作成することです。全体的に、それは正常にすべてのURLの90%を開くが、それはテキストエリアで7/10のURLを開くだけの時間の10%です。また、jquery 2.2.3は、textareaの値を取得するために使用されます。Chrome拡張機能のループが一貫しない

私はどのように/時にはテキストエリアで7/10のURLを開いて、それを修正できるのかを理解しようとしています。マニフェスト、popup.html、およびbackend.jsは以下のとおりです。

backend.js:

function urltoTabs(){ 
var text = $('textarea').val().split('\n'); 
    for (var h = 0; h <= text.length; h++) { 
    if (text[h].length < 1) continue; 
    chrome.tabs.create({url:text[h]}); 
    } 
} 
document.addEventListener('DOMContentLoaded', function() { 
    document.getElementById('engage').addEventListener('click', urltoTabs); 
}); 

popup.html:

<!DOCTYPE html> 
<html> 
    <head> 
     <script type="text/javascript" src="jquery-2.2.3.min.js"></script> 
     <script type="text/javascript" src="backend.js"></script>  
    </head> 
    <body> 
     <form> 
      <p><strong>List urls below<strong><br /> 
      <textarea id="textarea" rows="15"></textarea></p> 
      <button id="engage">Engage!</button> 
     </form> 
    </body> 
</html> 

manifest.jsonを:

{ 
    "manifest_version": 2, 
    "name": "Link to Tabs", 
    "short_name": "Link To Tabs", 
    "description": "Test url to tabs.", 
    "version": "0.0.4", 
    "minimum_chrome_version": "38", 
    "content_scripts": [ 
    { 
     "matches": ["*://*/*"], 
     "js": ["backend.js"] 
    }], 

    "permissions": [ 
      "tabs" 
     ], 

    "browser_action": { 
      "default_icon": {      
      "19": "assets/icon_16.png"   
      }, 
      "default_title": "New Tabs!",  
      "default_popup": "popup.html"   
     }, 

    "icons": { 
    "16": "assets/icon_16.png", 
    "128": "assets/icon_128.png" 
    } 
} 

私はこの上の任意の助けに感謝!

+0

毎回同じURLを使用していますか? – flapjack17

+0

いいえ、ユーザー入力に固有です。 例: https://www.google.com/1 https://www.google.com/2 https://www.google.com/3 https://www.google.com/4 https://www.google.com/5 https://www.google.com/6 https://www.google.com/7 https://www.google.com/8 https://www.google.com/9 https://www.google.com/10 – Chad

+0

大丈夫、コピー&ペーストリストでテストしていたのかどうかは不明です。うーん、ループはうまく動作し、私が考えることができるのはクロムでハングアップすることだけです。おそらく、タブの作成ごとにsetTimeoutで遅延を入れてみてください。 setTimeout(function(){chrome.tabs.create({url:text [h]});}、h * 200); – flapjack17

答えて

0

回答クレジットは問題はタブが途中で操作を閉じることになる作成された後、ポップアップが閉じてしまうだった@狼-戦争

に行きます。 popup.htmlとbackend.jsをバックグラウンドにプッシュすると、この問題が修正されました。変更されたのはマニフェストです。

manifest.jsonを:すべての助けを

{ 
    "manifest_version": 2, 
    "name": "Link to Tabs", 
    "short_name": "Link To Tabs", 
    "description": "Test url to tabs.", 
    "version": "0.0.4", 
    "minimum_chrome_version": "38", 
    "background": { 
    "js": "backend.js", // Needs both js and html to store user input correctly 
    "page": "popup.html" 
    }, 
    "permissions": [ 
      "tabs" 
     ], 
     //content_scripts was removed 
    "browser_action": { 
      "default_icon": {      
      "19": "assets/icon_16.png"   
      }, 
      "default_title": "New Tabs!",  
      "default_popup": "popup.html"   
     }, 

    "icons": { 
    "16": "assets/icon_16.png", 
    "128": "assets/icon_128.png" 
    } 
} 

おかげで、私は本当に感謝します!

関連する問題