0

We have a chrome extension that's been working fine with manifest V2, which we've recently tried to migrate to manifest v3 (https://developer.chrome.com/docs/extensions/mv3/intro/) We got everything working (as in, it runs, and almost everything works). However, we have a single issue, where we're listening for a Chrome event (printerProvider.onPrintRequested(https://developer.chrome.com/docs/extensions/reference/printerProvider/#event-onPrintRequested) to be more exact) performs a few Ajax requests,and then tries to upload a document, however, the upload request will sometimes, seemingly randomly, stay in pending state, and the result callback will never trigger. The minimum example I've been able to reproduce the issue on, is the below.

chrome.printerProvider.onPrintRequested.addListener(
  function (printJob, resultCallback) {
    let createdJob = {
        uploadLink: "$VERY_LONG_SIGNED_URL",
        "uploadHeaders": {
          "x-ms-blob-type": "BlockBlob"
        }
      };
    console.log("Printing job", printJob)
    uploadJob(createdJob, printJob)
     .then(function (uploadResponse) {
       console.log("Job " + uploadResponse + " was uploaded ");
       resultCallback("OK");
     }).catch(function(err){
       resultCallback("FAILED");
     });
});



uploadJob: function (jobMetadata, printjob){
  var headers = new Headers();
  if (createdJob.uploadHeaders) {
      var p = jobMetadata.uploadHeaders;
      for (var key in p) {
        if (p.hasOwnProperty(key)) {
          headers.append(key, p[key]);
        }
      }
    }
  return fetch(jobMetadata.uploadLink, {
      headers: headers,
      method: "PUT",
      body: printjob.document
    })
}

This will work some of the time (something like 50/50 success) and sometimes the fetch request will just stay pending and the code never completes, so I'm pretty sure it must be something I'm misunderstanding wrt. the way promises work, or the fact that Manifest V3 runs everything in a webworker instead of in a background page as V2 did.

4

0 回答 0