Почему в библиотеке, вставленной в фоновый скрипт, отсутствуют методы-прототипы? - PullRequest
0 голосов
/ 29 февраля 2020

Я внедряю пользовательскую библиотеку в фоновый скрипт в моем chrome расширении. В прототипе объекта есть методы, но когда я тестирую свое расширение, он говорит, что метод, который я вызываю, не определен. Я открываю отладчик и обнаруживаю, что все мои методы-прототипы библиотек отсутствуют. Вот мой манифест:

{
  "name": "Travelers Learning",
  "version": "1.0",
  "description": "Chrome extension to enable xAPI",
  "background": {
    "scripts": ["tx.js", "main.js"],
    "persistent": true
  },
  "permissions": [
    "activeTab",
    "tabs"
  ],
  "content_scripts": [
    {
      "run_at": "document_end",
      "matches": ["http://*/*", "https://*/*"],
      "js": [ "ramda.js", "tincan.js", "interactionProfile.js", "tx.js", "all.js"]
    },
    {
      "run_at": "document_end",
      "matches": ["*://*.youtube.com/*"],
      "js": ["interactionProfile.js", "tx.js", "youtube.js"]
    }
  ],
  "browser_action": {
    "default_popup": "main.html"
  },
  "manifest_version": 2
}
//all.js

chrome.runtime.sendMessage({contentScriptQuery: ''}, (tx) => {


// This callback catches a newly created instance of my tx library, it has some variables on it but the prototype methods are missing. The prototype methods are missing from any sub objects too.

    tx.registerProfile('launched', interactionProfile);
    tx.sendStatement('launched', {
        verbLabel: 'experienced',
        userEmail: tx.getUserId(),
        UUID: tx.getUUID(),
        objectID: 'Page Title',
        objectDisplayName: 'Page Title',
        iriRoot: 'http://adlnet.gov/expapi/verbs/'
    });

});

//main.js

chrome.tabs.onActivated.addListener(function (tabInfo){
    chrome.tabs.get(tabInfo.tabId, function(tab) {
        console.log(tab);
    });
});

chrome.runtime.onMessage.addListener(
    (request, sender, sendResponse) => {
        tx.TX.create({
            endpoint: '*****',
            username: '*****',
            password: '*****',
            allowfail: false,
            env: "sandbox",
            xapiEndpoint: '*****'
        })
            .then((tx) => {
                // Prototype methods are still present here.
                return sendResponse(tx)
            });
        return true;
    });

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...