Getting started with chrome.printing API

Cancel a print job

Task 6

5 minutes

Finally, you need to give the user the ability to cancel a print job.

To cancel a print job before completion, you will call cancelJob with jobId as parameter.

Add the following function to printers.js:

function onCancelButtonClicked(jobId) {
  chrome.printing.cancelJob(jobId).then((response) => {
    if (response !== undefined) {
      console.log(response.status);
    }
    if (chrome.runtime.lastError !== undefined) {
      console.log(chrome.runtime.lastError.message);
    }
  });
}

Now you should have a running Chrome extension that can:

  • List all available printers.
  • Send a print job to a printer.
  • Monitor print job status.
  • Cancel a print job.

If you want to see a full version of a sample Chrome extension for printing please see this Github repo.

Your turn