0

I have added a file in the manifest like the below code.

manifest

content_scripts": [ {
  "js": [ "/js/inside.js" ],
  "matches": [ "*://*.google.com/*" ]
} ],

inside.js

var scriptTag = document.createElement("script");
scriptTag.type = "text/javascript";
scriptTag.src = "chrome-extension://" + chrome.runtime.id + "helper.js";
var scriptTags = document.getElementsByTagName("script")[0];
scriptTags.parentNode.appendChild(scriptTag, scriptTags)

helper.js

window.sendImg(imgFile, caption, done = undefined) {
  return window.Store.Chat.find(setPhone(this.phone) + "@c.us").then(chat => {
    let mc = new window.Store.MediaCollection(chat);
    mc.processAttachments([{ file: imgFile }, 1], chat, 1).then(() => {
      let media = mc.models[0];
      media.sendToChat(chat, { caption: caption });
      if (done !== undefined) done(true);
    });
  });
};

background.js

window.sendImg(imgFile, capt);

It is not calling, showing error window.sendImg is not defined

enter image description here

iAmOren
  • 2,760
  • 2
  • 11
  • 23
Pooyan Pal
  • 13
  • 4
  • The background script runs in its own hidden background page. It's like a hidden tab that has its own life cycle: it runs when the extension is loaded, installed, re-enabled, or when resumed in case the background script was declared with "persistent":false. You don't need it here. You currently add the code into [page context](/a/9517879) so only the code in that context can access it like helper.js. – wOxxOm Jul 30 '20 at 20:11
  • @wOxxOm, can you please help? Some data are store in background , may be not access in context page, how can I arrange code so that function will execute. – Pooyan Pal Jul 31 '20 at 02:18
  • I can't help using your current code: like I said it doesn't need background.js at all. – wOxxOm Jul 31 '20 at 04:11

0 Answers0