1

i am injecting various script's and css from chrome extension, below is my snippet code,

Background.js

function start() {
    var tab = JSON.parse(localStorage.getItem('tab'));
    chrome.tabs.insertCSS(tab.id, { file: 'assets/css/style.css' })
    chrome.tabs.executeScript(tab.id, { file: 'assets/lib/jquery-1.8.2.min.js' }, function () {
        chrome.tabs.executeScript(tab.id, { file: 'assets/lib/jquery-ui.min.js' }, function () {
                chrome.tabs.executeScript(tab.id, { file: 'js/inject/inject.js'});
        });
    });
}

chrome.browserAction.onClicked.addListener(function (tab) {
    start();
});

Inject.js

(function(){
     jQuery(document).ready(function () {
          console.log("Document Loaded!!");
          jQuery("#Table td").click(function() {     
              var column_num = parseInt( $(this).index() ) + 1;
              var row_num = parseInt( $(this).parent().index() )+1;    
              console.log(column_num, row_num);
          });
     });
})();

now the problem is that when i am opening extension second time jQuery stops working and throwing error of

Uncaught TypeError: jQuery is not a function

or

Uncaught TypeError: jQuery is undefined

I need to find if it is possible to check that my inject.js has already been executed then on reopening extension i just need to call other functions.

Nasiruddin Saiyed
  • 1,438
  • 1
  • 13
  • 31
  • Probably, you have a typo here `{ file: 'js/inject/inject.});` You forgot to add single quote. – Aefits May 02 '18 at 07:20
  • Its just snippet code is vast different and i just want to check that my inject.js is already executed or not – Nasiruddin Saiyed May 02 '18 at 07:45
  • Check out this SO post https://stackoverflow.com/q/34528785/1225070 – Aefits May 02 '18 at 08:54
  • Possible duplicate of [Chrome extension: Checking if content script has been injected or not](https://stackoverflow.com/questions/34528785/chrome-extension-checking-if-content-script-has-been-injected-or-not) – MatthewG May 05 '18 at 03:06

0 Answers0