javascript - Crossrider external js file not loading :PDFJS is not defined -


below codes in extension.js. if @ codes, tried different ways load file extension. no matter what, getting

vm3051:15 uncaught referenceerror: pdfjs not defined

tried putting file in different locations.

appapi.ready(function($) {   console.log("pdf min js loading");   appapi.resources.includejs('jspdf.js');  // appapi.resources.includejs('js/jspdf.js'); // appapi.resources.includeremotejs('//cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js');  //$.globaleval(appapi.resources.get('//cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js'));  console.log("done");     settimeout(function(){         alert(window.location.href);     if(window.location.href.indexof(".pdf") > -1) {         console.log("its pdf");          alert("pdf");         var doc = new jspdf();      }else{     alert($.trim($('div').find('h1,h2,h3,h4,h5,p,span').text()));     }      },6000); }); 

here file structure

enter image description here

i cannot modify manifest.json because extension should unique browsers not chrome.

i'm confused, 2 cloudflare urls in code reference project jspdf. assume local pdf.js same too.

in code, you're using

pdfjs.getdocument(); 

this syntax comes pdf.js totally different project mozilla.

if you're sticking jspdf, code should like:

var doc = new jspdf(); doc.text(20, 20, 'hello world.'); doc.save('test.pdf'); 

or you'll need include correct library pdf.js.

after edits you've made , comments, seems you've switch on jspdf you're still getting same error mentions pdf.js.

are sure you're debugging correct , last version of app using jspdf?

i've setup small reproduction example on crossrider using jspdf.

project structure

the extension.js code following:

appapi.ready(function($) {   console.log("pdf min js loading");    appapi.resources.includejs('jspdf.js');    console.log("done");    var doc = new jspdf();    console.log(doc); }); 

when debugging extension, i'm getting result:

output

doc object containing instance of jspdf can later use.

there should no mention of pdf.js whatsoever. guess you're running / debugging version of extension still containing references project.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -