현재 활성 탭의 탭 ID 및 탭 URL을 표시하려고합니다. 그러나 모든 경고문 (1,2 및 3)에 주석을 달면 예상대로 결과가 표시되지 않습니다. . 예 : 모든 경고문을 주석 처리 한 후 처음으로 ALT + A를 누르면 변수가 초기화되지 않았다는 것을 의미하는 URL의 null 값과 ID 필드의 0이 생깁니다. //TabBackGround.js 크롬 확장 - 알림 문이 결과를 변경합니다.
var currentTabId = 0;
var currentTabURL = "null";
chrome.commands.onCommand.addListener(function(command) {
alert ("1. Inside Listener"); //1
chrome.tabs.query({active:true, currentWindow: true}, function(arrayOfTabs) {
alert("2. Filtering Results"); //2
currentTabURL = arrayOfTabs[0].url;
currentTabId = arrayOfTabs[0].id;
});
if (command == "toggle")
{
alert ("3. Resolved Command"); //3
alert ("TAB ID = " + currentTabId + "\n URL = " + currentTabURL);
}
});
그러나, 나는 모든 경고 문을 유지하는 경우 확장이 잘 작동합니다. 내가 이해할 수없는 것은 경고문이 최종 결과에 어떤 차이가 있는지입니다. ! 주의 할 //Manifest.json
{
"manifest_version": 2,
"name": "Display Tab Information",
"description": "Extension will display Tab Id and Tab URL in an alert box",
"version": "1.0",
"background": {
"persistent": false,
"scripts": ["TabBackGround.js"]
},
"commands":
{
"toggle" :
{
"suggested_key": {
"default": "Alt+A",
"mac": "Command+Shift+Y"
},
"description" : "Display Id and URL of the current open/active tab."
}
},
"permissions": ["tabs", "background"],
"browser_action": {
"default_title": "This App will display Tab Id and Tab URL when user issues the command.",
"default_icon": "hello.png"
}
}
또 다른 점은 var에 currentTabId = 0; var currentTabURL = "null";
chrome.commands.onCommand.addListener (함수 (명령) {
//alert ("1. Inside Listener");
chrome.tabs.query({active:true, currentWindow: true}, function(arrayOfTabs) {
alert("2. Filtering Results");
currentTabURL = arrayOfTabs[0].url;
currentTabId = arrayOfTabs[0].id;
});
if (command == "toggle")
{
alert ("3. Resolved Command" + "TAB ID = " + currentTabId + "\n URL = " + currentTabURL);
alert ("4. Check when does this get executed" + "TAB ID = " + currentTabId + "\n URL = " + currentTabURL);
alert ("TAB ID = " + currentTabId + "\n URL = " + currentTabURL);
}
});
3 (현재 아이디 = 0 CURRENTURL = null)와 다음 경고 2가 실행되었다과 전류 (ID)의 정확한 값과 현재 URL 4 다음 경고
아니기 때문에. 그것은 다른 문제입니다. https://stackoverflow.com/questions/26096646/flow-sequence-in-chrome-extension – Xan
미안하지만 회신을받지 못했습니다 !! 더 자세히 설명해 주시겠습니까? –
알았어. 다른 경고문들에 관한 것이 아니라 실행될 때 CurrentTabURL과 CurrentTabIf에 초기화 될 기회를주는 경고 3이다. 경고문을 사용하는 대신 동일한 작업을 수행 할 수 있습니까? –