0

Chrome 확장 프로그램을 만들고 있는데 콘텐츠 스크립트 및 메시지 전달 방법에 대해 매우 혼란 스럽습니다. 아래에서는 필자가 지금까지 가지고있는 확장과 코드의 목표에 대해 자세히 설명합니다.콘텐츠 스크립트 및 메시지 전달을 사용하여 웹 사이트에서 메타 데이터를 수집하고 Chrome 확장 프로그램으로 다시 보내려면 어떻게해야합니까?

연장은 할 필요가 :

  1. 는 모든 웹 페이지에 대한 활성화
  2. 의 확장으로 다시 메타 데이터를 통신 사용자가
  3. 에 각 사이트에서 메타 데이터를 (특히 키워드) 수집 확장 기능이 키워드를 분석하고 그에 따라 작동 할 수있는 방법입니다. 나는에 일반 텍스트를 얻을 수 확장, 나는 popup.html의 코드를 포함하지 않은 사이트의 카테고리 (즉, 소셜 미디어, 블로그, 스포츠 사이트)]

에 따라 다른 텍스트를 표시합니다 내 확장 아이콘을 클릭하면 팝업 창이 나타납니다.

내 파일까지 :


manifest.json을

"manifest_version": 2, 
"name": "my extension", 
"description": "This is my first chrome extension.", 
"version": "1.0", 

"content_scripts": [ {"matches": ["<all_urls>"], "run_at": "document_end", "js["testscript.js"] }], 

"permissions": ["tabs", "http://*/*", "background"], 

"background": "background.html", 

"browser_action": { "default_icon": "my_logo.png", "default_popup": "popup.html" } 

contentscript.js

var meta_keywords = getKeywords(); 

chrome.extension.sendRequest(meta_keywords); 

function getKeywords() { 
    data = document.getElementsByTagName("meta"); 
    keywords = []; 
    var len = data.length; 
    for (var i = 0; i < len; i++) { 
    if (data[i].name == 'keywords') { 
     keywords = data[i].content.split(","); 
    } 
    } 
    return keywords; 
} 

background.html

//I really have no idea what this means or how to use it... 
//I just know that I need some sort of onRequest function 

chrome.extension.onRequest.addListener(function(keywords, sender, sendResponse) {}) 

모든 모든 도움을 크게 감상 할 수있다. 수많은 자습서와 Google 설명서를 읽었지만 지금은 이해하지 못하고 있습니다. 미리 감사드립니다.

+0

어떤 문서를 사용하셨습니까? 귀하의 질문에 사용 된 API 형식은 Chrome 버전 10 개 이상 사용이 중단되었습니다. 최신 버전을 얻으려면 [배경 페이지] (https://developer.chrome.com/extensions/background_pages.html) 문서를 읽고 ['chrome.runtime.sendMessage'] (https : // developer를 사용하십시오. chrome.extension. * 대신 .chrome.com/extensions/runtime.html # method-sendMessage)/['onMessage'] (https://developer.chrome.com/extensions/runtime.html#event-onMessage) '. –

답변

0

몇 달 전에 나는

https://github.com/ruddog/chrome-devtools-skeleton/

는 당신

을 위해 도움이 될 것입니다 희망을 살펴이 배경 페이지의 콘텐츠 페이지와 DevTools로 페이지 사이의 메시징을 DevTools로 확장 에 대한 싱글처럼 떨어지게을 만들려고