The response from the service worker fetch did not include the "Content-Length" header

Currently, I am fetching static assets such as images and PDFs from AWS S3 and providing download progress updates to the client using the service worker API. My method involves reading the "content-length" header in the response. Interestingly, this approach works seamlessly in Chrome Canary (version 77.0.3821.0), but I have encountered issues with Firefox (version 67.0) and Chrome (version 75.0.3770.80) as they do not include the "content-length" header in the response.

While referencing this answer on Stack Overflow, setting the request.mode to "cors" did provide some initial success, albeit limited to Chrome Canary at the moment.

Within the function respondWithProgressMonitor(clientId, response):
for key in response.headers.keys():
console.log(key); // In Chrome and Firefox, only "content-type" and "last-modified" are returned, whereas Chrome Canary also includes "content-length".

const contentLength = response.headers.get('content-length');

// ...

Function fetchWithProgressMonitor(event):
const request = new Request(event.request.clone(), {
mode: 'cors',
credentials: 'omit'
});
return fetch(request).then(response => respondWithProgressMonitor(event.clientId, response));

I have configured my S3 bucket's CORS rules to expose the required header unless I am overlooking something.

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <CORSRule>

    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>HEAD</AllowedMethod>
    <AllowedHeader>*</AllowedHeader>
    <ExposeHeader>Content-Length</ExposeHeader>
  </CORSRule>
</CORSConfiguration>

I am puzzled by the fact that the content-length header is present in the Canary response but absent in the current Chrome release or Firefox. Are there specific options that I should include in my request to ensure a "content-length" header is included in the response? Any guidance or suggestions would be greatly appreciated.

Answer №1

Instead of providing a direct answer, here is a workaround solution: Place the content size in a separate header. Consider using 'x-content-length-visible' as the name for this header, which may not be intercepted by the serviceworker.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Strategies for aligning the initial lines of text vertically within a table cell

I am faced with a unique challenge involving a table where the first cell contains the word "name" and the second cell contains some text. Sometimes, this text may include embedded images. The issue arises when an image appears on the first line of the tex ...

Looping through multiple ajax requests to track the most recent responses

Run a loop with the most recent response obtained from the previous ajax call. The current code is continuously displaying the same response. PHP outputs data in text format. Currently, the code fetches response text from the PHP file and appends it to a ...

Attempting to incorporate icons into a Material UI table design

Hello, I've incorporated a Material UI table into one of my projects with a design concept similar to this - https://i.stack.imgur.com/i6Fsj.png I'm aiming to include icons within the tables. Here's the code I've worked on so far - ...

Unveiling the Wonders of Cordova Consumable Product In-App

My question is this: if I purchase a consumable product, such as coins, do I need to update my database with the purchased coins using ajax? How can I ensure the security of the ajax request when it comes to buying it through InApp Purchase? Is it possib ...

Show or conceal a child component within a React application

In my React render function, I am working with the following code: <div> <InnerBox> <div>Box 1</div> <HiddenBox /> </InnerBox> <InnerBox> <div>Box 2</div> & ...

How can I change the default selected option for a radio button in a React application?

I am having trouble setting the default checked radio button to lime in my radio button group. Even though I have set lime as the default value, it doesn't seem to work. Here is the code snippet that I am working with and I am looking for a solution ...

What is the best way to display the success message within the if statement once the values are retrieved from an Ajax request?

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.net.*" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <!DO ...

Another return payload failing to retrieve the return value

I'm currently facing an issue where a function that should return a value is not being passed on to another function. Below is the code snippet in question: public _getProfileToUpdate() { return { corporateId: this.storeService.setStoreData().p ...

Struggling to generate a functional link with Laravel and Vue?

For the past few days, I've been facing a problem. The issue I'm encountering is this: I have created a link in my .vue page to download a simple PDF file: <a href= {{ asset('download/form.pdf') }}> Download here. </a> (Th ...

Is there a way to determine which option is currently highlighted in Internet Explorer before it is actually chosen?

Despite the fact that IE does not support mouse events on <option> elements, it does highlight the option under the mouse cursor when you open a dropdown list. Is there a way in JavaScript to capture this highlighted option as the user moves the mous ...

Update the value in JSON upon the click of a button

Currently, I am dealing with a nested buttonclick situation inside another buttonclick. Right now, my alert is working fine. $scope.getid = function (order) { $scope.chosen.id = order.id; $scope.chosen.status = order.point ...

When trying to install express using Node.js npm, an error message 'CERT_UNTRUSTED' is preventing the installation of express

My goal is to set up express on Raspberry Pi for the purpose of using it in a REST API. However, I keep encountering an issue with SSL certification when trying to install it through npm. Despite attempting various solutions found on different forums, I ha ...

Ensure that the dynamically inserted <title> tag remains intact in Angular even when the page is re

Can the dynamic title tag be preserved when the page is refreshed? When I refresh the page, the title tag reverts back to the original one specified in the index.html temporarily before switching back to the dynamically added one. I want the title tag to ...

Exploring the power of Nestjs EventEmitter Module in combination with Serverless functions through the implementation of Async

I am working on implementing an asynchronous worker using a serverless lambda function with the assistance of the nestjs EventEmitter module. The handler is being triggered when an event is emitted, but the function closes before the async/await call. I ...

What is the best way to populate data with Angular framework in my specific situation?

I'm currently working with Angular and attempting to implement a pagination feature. Here is what I have so far: Angular controller appModule.controller('testCtrl', ['$scope', function ($scope) { $scope.numbers = 7; }]) html ...

By implementing setInterval, but I aim to deactivate it upon detecting user input

Currently, I have a function being called using setInterval that loads my page via an ajax get request and displays the response in real-time like a live updates page. The issue arises when users are inputting data into the form because the page is refresh ...

Adding a player object to a Phaser scene using JavaScript

Just starting out with Phaser js and attempting to create a game using Object-Oriented Programming. The challenge I'm facing is trying to load my character into the scene, but nothing seems to be happening. No errors or exceptions are being thrown. I& ...

Unable to execute PHP code within a PHP file loaded through AJAX

I'm currently in the process of developing a webshop using WooCommerce. I have successfully implemented two switch buttons that allow users to toggle between 'List view' and 'Grid view'. Specifically, for the list view button, I am ...

Creating a portlet with JSF and integrating AJAX functionality on Websphere Portal 7, using RAD 8

I am trying to create a JSF portlet with AJAX but I am having trouble getting it to render properly. I attempted to follow the example provided by IBM at , but it only seems to work in WebSphere Application Server (WAS) and not in WebSphere Portal. I have ...

Incorporate hover, onmouseover, and onmouseout features into a CSS class with proper syntax

I'm struggling with the fundamentals of syntax. I am attempting to utilize jQuery in order to target all elements within a certain CSS class, and then apply a function when the user hovers over the item. $(".item").hover(function(){$(this).fadeTo(100 ...