Repository: electron/electron
Pull request: feat!: remove support for ProtocolResponse.session null value

#### Description of Change

BREAKING CHANGE

This feature was deprecated in f7ba0d3b (#46131). This PR removes it for Electron 37.

It's being removed because we should discourage single-use sessions. They allocate resources that stick around forever due to bac2f46.

#### Checklist

- [x] PR description included and stakeholders cc'd
- [x] `npm test` passes
- [x] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).

#### Release Notes

Notes: Removed deprecated feature of creating a new random session by setting `ProtocolResponse.session`'s property to `null`.

Changed files:
filename: docs/api/structures/protocol-response.md
patch: @@ -25,11 +25,8 @@
   and URL responses.
 * `method` string (optional) - The HTTP `method`. This is only used for file
   and URL responses.
-* `session` Session (optional) - The session used for requesting URL, by default
-  the HTTP request will reuse the current session. Setting `session` to `null`
-  would use a random independent session. This is only used for URL responses.
-  **Deprecated:** Using `null` to create a random independent session is
-  deprecated and will be removed soon.
+* `session` Session (optional) - The session used for requesting URL.
+  The HTTP request will reuse the current session by default.
 * `uploadData` [ProtocolResponseUploadData](protocol-response-upload-data.md) (optional) - The data used as upload data. This is only
   used for URL responses when `method` is `"POST"`.
 

filename: docs/breaking-changes.md
patch: @@ -14,6 +14,18 @@ This document uses the following convention to categorize breaking changes:
 
 ## Planned Breaking API Changes (37.0)
 
+### Removed: `null` value for `session` property in `ProtocolResponse`
+
+This deprecated feature has been removed.
+
+Previously, setting the `ProtocolResponse.session` property to `null`
+would create a random independent session. This is no longer supported.
+
+Using single-purpose sessions here is discouraged due to overhead costs;
+however, old code that needs to preserve this behavior can emulate it by
+creating a random session with `session.fromPartition(some_random_string)`
+and then using it in `ProtocolResponse.session`.
+
 ### Behavior Changed: `BrowserWindow.IsVisibleOnAllWorkspaces()` on Linux
 
 `BrowserWindow.IsVisibleOnAllWorkspaces()` will now return false on Linux if the

filename: shell/browser/net/electron_url_loader_factory.cc
patch: @@ -13,7 +13,6 @@
 #include "base/containers/fixed_flat_map.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/task/sequenced_task_runner.h"
-#include "base/uuid.h"
 #include "base/values.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/storage_partition.h"
@@ -671,20 +670,11 @@ void ElectronURLLoaderFactory::StartLoadingHttp(
       request->method != net::HttpRequestHeaders::kHeadMethod)
     dict.Get("uploadData", &upload_data);
 
-  auto* browser_context = ElectronBrowserContext::GetDefaultBrowserContext();
-  v8::Local<v8::Value> value;
-  if (dict.Get("session", &value)) {
-    if (value->IsNull()) {
-      browser_context = ElectronBrowserContext::From(
-          base::Uuid::GenerateRandomV4().AsLowercaseString(), true);
-    } else {
-      gin::Handle<api::Session> session;
-      if (gin::ConvertFromV8(dict.isolate(), value, &session) &&
-          !session.IsEmpty()) {
-        browser_context = session->browser_context();
-      }
-    }
-  }
+  gin::Handle<api::Session> session;
+  auto* browser_context =
+      dict.Get("session", &session) && !session.IsEmpty()
+          ? session->browser_context()
+          : ElectronBrowserContext::GetDefaultBrowserContext();
 
   new URLPipeLoader(
       browser_context->GetURLLoaderFactory(), std::move(request),