Google chrome extension 为什么我注入后台脚本的库丢失了它';什么是原型方法?

Google chrome extension 为什么我注入后台脚本的库丢失了它';什么是原型方法?,google-chrome-extension,Google Chrome Extension,我在chrome扩展的后台脚本中注入了一个自定义库。对象的原型上有一些方法,但当我测试扩展时,它会说我调用的方法未定义。我打开调试器,发现我所有的库原型方法都丢失了。这是我的舱单: { "name": "Travelers Learning", "version": "1.0", "description": "Chrome extension to enable xAPI", "background": { "scripts": ["tx.js", "main.js"]

我在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;
    });