0

Code hasn't changed since 2015. As of December the chrome extension stopped working. I can't figure out why.

Manifest has:

"web_accessible_resources": [ "script.js" ]

Content Script has:

var readDiv = $("div[id*=fls_readheader]");

$("table[id*='objects_tabs_detail']").filter(function(index){ return $("thead:first-of-type > tr:first-of-type > th:first-of-type > div:first-of-type", this).html() === "Field Name";}).find(readDiv).append("<br /><div style='margin-top:3px;'><input type='checkbox' name='Check All Read' onclick='clickAllRead(this);' /></div>");

var s = document.createElement('script');
    s.src = chrome.extension.getURL('script.js');
    s.onload = function() {
        this.parentNode.removeChild(this);      
    };
    (document.head||document.documentElement).appendChild(s);    

When I click on the checkbox I get the message:

Uncaught ReferenceError: clickAllRead is not defined at HTMLInputElement.onclick

Any ideas why this broke and how to fix it?

script.js contains:

function clickAllRead(cb) {
  if(cb.checked) {
    var cbs = $("input:checkbox:enabled[id*=fls_read_ck]");

    $("table[id*='objects_tabs_detail']").filter(function(index){ return $("thead:first-of-type > tr:first-of-type > th:first-of-type > div:first-of-type", this).html() === "Field Name";}).find(cbs).prop('checked', true);
  } else {
    var cbs = $("input:checkbox:enabled");

    $("table[id*='objects_tabs_detail']").filter(function(index){ return $("thead:first-of-type > tr:first-of-type > th:first-of-type > div:first-of-type", this).html() === "Field Name";}).find(cbs).prop('checked', false);
  }
}

If I add script.js to the "content_scripts" of the extension's manifest, the extension works as expected. I just want to know why it broke.

Ben Kean
  • 182
  • 1
  • 10
  • `clickAllRead` Where's this defined? On the destination HTML page? In that case, you need to check if the destination page has changed over time and update your references. – Praveen Kumar Purushothaman Jan 29 '19 at 15:13
  • Sorry, script.js contains the definition for clickAllRead. I should have mentioned that – Ben Kean Jan 29 '19 at 15:15
  • 1
    It would be worth if you can share us the code for `script.js` too. – Praveen Kumar Purushothaman Jan 29 '19 at 15:16
  • added script.js – Ben Kean Jan 29 '19 at 15:17
  • Seems to be some updated info on how to include these. [Manifest - Web Accessible Resources - Google Chrome](https://developer.chrome.com/extensions/manifest/web_accessible_resources) – Praveen Kumar Purushothaman Jan 29 '19 at 15:18
  • Thanks @PraveenKumarPurushothaman I've researched the manifest spec and I don't see how the instructions have been updated in a way that breaks this extension. If I add script.js to the "content_scripts" of the extension's manifest, the extension works as expected. I just want to know why it broke. – Ben Kean Jan 29 '19 at 15:27
  • 1
    This is a https://crbug.com/912069 in Chrome 71 only. You'll have to assign the attributes inside a [page-level code](https://stackoverflow.com/a/9517879) - inside script.js in your case. The bug is fixed in Chrome 72. – wOxxOm Jan 29 '19 at 15:38
  • @wOxxOm Thanks for reporting the bug! – Ben Kean Jan 29 '19 at 16:03

0 Answers0