0

Windows OS와 잘 작동하는 Google 크롬 확장 프로그램을 개발했습니다. 하지만 맥에서 작동하지 않는 문제가, 내가 Mac에서 작동하지 않는 기능을 Chrome 확장 프로그램 'executeScript'가 Mac에서 작동하지 않습니다.

chrome.tabs.executeScript 

을 발견,이 문제를 확인하려고,이 창하지 맥과 함께 좋은 일을 완전히 코드입니다.

// The onClicked callback function. 
function onClickHandler(info, tab) { 
       // the problem in injecting code 
       chrome.tabs.executeScript 
       (null,{code:"var activeElm = document.activeElement; var inp_text = activeElm.value; console.log(activeElm.value);"}); 
}; 

chrome.contextMenus.onClicked.addListener(onClickHandler); 

// Set up context menu tree at install time. 
chrome.runtime.onInstalled.addListener(function() { 
    // Intentionally create an invalid item, to show off error checking in the 
    // create callback. 
    console.log("About to try creating an invalid item - an error about " + 
     "duplicate item child1 should show up"); 
    chrome.contextMenus.create({"title": "consoleMe", "id": "child523", "contexts":["selection"]}, function() { 
    if (chrome.extension.lastError) { 
     console.log("Got expected error: " + chrome.extension.lastError.message); 
    } 
    }); 
}); 

힌트 :

나는 매니페스트 파일에 content_scripts 주입 파일을 사용하지만, Mac의 경우 Google 크롬에 활성화되지 않은 것 같다.

"content_scripts": [ 
    { 
     "matches": ["http://*/*","https://*/*"], 
     "js" : ["jquery.min.js","fix.js","injscript.js"], 
     "all_frames": false 
    } 
    ], 

OS : 맥 10.8 산 사자 - 구글 크롬 V (32)

답변

1

Windows와 Mac 사이에 차이점이 없습니다. 두 가지 설정간에 다른 점이있을 수 있습니다.

위의 javascript 스 니펫이 백그라운드 스크립트인지 삽입 된 콘텐츠 스크립트인지는 분명하지 않습니다. 전체 매니페스트를 제공하고 스 니펫이 속한 파일을 나타낼 수 있습니까? 이 배경 스크립트가 있다면

  • , 널 (null) TABID와 chrome.tabs.executeScript는 기대하지 무엇 인 배경 페이지에 적용됩니다. 대신 tabId에 tab.id를 전달하십시오.

  • 콘텐츠 스크립트 인 경우 콘텐트 스크립트에 크롬 API를 사용할 수 없으므로 contextMenus API 호출이 작동하지 않습니다 (https://developer.chrome.com/extensions/content_scripts.html 참조).