BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Chrome 80 Released with New Cookie Policy, Module Workers and Optional Chaining

Chrome 80 Released with New Cookie Policy, Module Workers and Optional Chaining

This item in japanese

Google recently released Google Chrome 80. Chrome 80 provides several new features, including: important changes to its cookie policy; supporting modules in workers and optional chaining in JavaScript; adding new origin trials while graduating previous origin trials; supporting links directly to text fragments on a page with a new hashtag syntax; and more.

As already announced in May 2019, the Chrome browser (starting with version 80) now enforces a new secure-by-default cookie classification system, treating cookies that have no declared SameSite value as SameSite=Lax cookies. Cookies configured with SameSite=None; Secure remain available in third-party contexts, if secure connections are used to access them.

Module workers are web workers with the ergonomics and performance benefits of JavaScript modules. To use module workers, developers may use the Worker constructor with the {type: "module"} option. The new option changes script loading and execution to match <script type="module">'s:

const worker = new Worker('worker.js', {  type: 'module'});

Since module workers are standard JavaScript modules, they can use import and export statements. The new feature thus enables the use of dynamic import for lazy-loading code, without blocking the execution of the worker. The standard web worker’s importScripts, which is synchronous, is disabled for module workers.

Given that a module worker script is loaded, parsed and executed like any JavaScript modules, it can be preloaded and pre-parsed, which is difficult to achieve with standard web worker scripts:

<!-- preloads worker.js and its dependencies: -->
<link rel="modulepreload" href="worker.js">

<script>
  addEventListener('load', () => {
      // our worker code is likely already parsed and ready to execute!
          const worker = new Worker('worker.js', { type: 'module' });
  });
</script>

Chrome 80 now supports optional chaining in JavaScript. Optional chaining allows to write:

// Still checks for errors and is much more readable.
const nameLength = db?.user?.name?.length;

instead of:

// Less error-prone, but harder to read.
let nameLength;
if (db && db.user && db.user.name)  nameLength = db.user.name.length;

The Contact Picker API graduates from origin trials. The Contact Picker API lets users share contacts from their contact list with a website. Use cases include a web-based email client selecting necessary information about the recipients of an email, or voice over IP (VoIP) apps accessing the contact list to look up the phone number to call.

The Content Indexing API enters the origin trial phase (lasting from Chrome to Chrome 82, the latter scheduled for June 2020) as part of Chrome’s Capabilities project. The Content Indexing API is a web API by which websites may register their offline content with the browser. This allows the browser to improve offline capabilities and offer content to users to browse through while offline. The Chrome team explains:

The Content Indexing API is not an alternative way of caching content. It’s a way of providing metadata about pages that are already cached by your service worker, so that the browser can surface those pages when folks are likely to want to view them. The Content Indexing API helps with discoverability of cached pages.

Chrome 80 also improves linking by allowing users to link directly to text fragments on a page, by using the updated tag syntax #:~:text=something (for instance https://en.wikipedia.org/wiki/Rickrolling#:~:text=New%20York). Chrome will then scroll to and highlight the first instance of the specified text.

Some users reported initial formating issues when displaying web sites with Chrome 80, issues which appear to be now fixed. Some Angular users reported a bug with Array.reduce. At the time of publication of the article, a fix was found but has not been published yet. Angular released a new patch version in the meantime.

Chrome 80 additionally implements 56 security fixes. A complete list of features in origin trials is available in the release note. The developer tools also benefit from additional functionalities.

Rate this Article

Adoption
Style

BT