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