sᴜʀᴇsʜ ᴀᴛᴛᴀ sᴜʀᴇsʜ ᴀᴛᴛᴀ - 3 months ago 43x
Javascript Question

Crossrider external js file not loading :PDFJS is not defined

Below are my codes in extension.js. If you look at the codes, I tried different ways to load the file to my extension. No matter what, I always getting

VM3051:15 Uncaught ReferenceError: PDFJS is not defined

Tried with putting the file in different locations.

appAPI.ready(function($) {
console.log("pdf min js loading");
// appAPI.resources.includeJS('js/jspdf.js');
// appAPI.resources.includeRemoteJS('//cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js');
if(window.location.href.indexOf(".pdf") > -1) {
console.log("its a pdf");

var doc = new jsPDF();



Here is the file structure

enter image description here

I cannot modify
because the extension should be unique for all the browsers not just for chrome.


I'm confused, the two CloudFlare URLs in your code reference the project jsPDF. I would assume the local pdf.js does the same too.

In your code, you're using


This syntax comes from PDF.js which is a totally different project from Mozilla.

If you're sticking with jsPDF, your code should be something like:

var doc = new jsPDF();
doc.text(20, 20, 'Hello world.');

Or you'll need to include the correct library for PDF.js.

After the edits you've made and your comments, it seems you've switch completely over to jsPDF but you're still getting the same error which clearly mentions PDF.js.

Are you sure you're debugging the correct and last version of your app which is only using jsPDF?

I've setup a small reproduction example on Crossrider using only jsPDF.

Project structure

The extension.js code is the following:

appAPI.ready(function($) {
  console.log("pdf min js loading");



  var doc = new jsPDF();


When debugging the extension, I'm getting this result:


doc is an object containing an instance of jsPDF which I can later use.

There should be no mention of PDF.js whatsoever. My only guess could be that you're running / debugging a version of your extension still containing references to this project.