Skip to content

Conversation

@barjin
Copy link
Member

@barjin barjin commented Nov 12, 2025

Uses new implementations of createStorageContentSignature and createHmacSignature from @apify/utilities.

Those native WebCrypto API instead of importing the node:crypto package, so we can mark crypto as external in the browser bundler and cut the bundle size ~2.4 times (both plain and compressed).

before (master) after (perf/use-native-crypto)
image image

Note: SubtleCrypto API in browsers is only available in Secure Contexts. This should be fairly safe (as any https://-served page is one, as well as localhost).

Related to #753

@barjin barjin self-assigned this Nov 12, 2025
@github-actions github-actions bot added this to the 127th sprint - Tooling team milestone Nov 12, 2025
@github-actions github-actions bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Nov 12, 2025
Copilot finished reviewing on behalf of barjin November 12, 2025 13:09
@barjin barjin added the adhoc Ad-hoc unplanned task added during the sprint. label Nov 12, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the browser bundle by replacing Node.js crypto implementations with native WebCrypto API equivalents from @apify/utilities, reducing bundle size by ~2.4x. The key changes involve switching from synchronous crypto signature functions to asynchronous WebCrypto-based implementations and marking the Node.js crypto module as external in the browser bundler configuration.

  • Updated signature generation functions to use async WebCrypto API implementations
  • Added browser-based tests to verify cryptographic operations work correctly in secure contexts
  • Upgraded @apify/utilities from 2.18.0 to 2.23.0 to access the new async crypto functions

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/resource_clients/key_value_store.ts Switched to async signature functions (createHmacSignatureAsync, createStorageContentSignatureAsync) with proper await usage
src/resource_clients/dataset.ts Updated to use createStorageContentSignatureAsync with await
test/key_value_stores.test.js Added browser tests for getRecordPublicUrl() and createKeysPublicUrl() to verify WebCrypto implementation works in browsers
test/datasets.test.js Added browser tests for createItemsPublicUrl() to verify WebCrypto implementation works in browsers
test/_helper.js Enhanced getInjectedPage() to navigate to URLs ensuring secure context required for Web Crypto API
rsbuild.config.ts Marked crypto as external to prevent bundling Node.js crypto module in browser builds
package.json Upgraded @apify/utilities dependency to version 2.23.0
package-lock.json Updated lock file to reflect new @apify/utilities version (2.23.0)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@barjin barjin marked this pull request as draft November 12, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants