Skip to content

Commit

Permalink
[0.1.10] Fix use of modern ES features for some Safari/iPhone versi…
Browse files Browse the repository at this point in the history
…ons (#21)

* Specifically target `es6`, avoid optional chaining, bump to `0.1.10`

* Avoid the use of spread operator

* Increase timeouts in sdktest, handle context cancellation after timeout
  • Loading branch information
gzuidhof authored Nov 28, 2024
1 parent dd6e012 commit 5f6f267
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# changelog

## 0.1.10

* Fix use of ES features in non-compat build, which caused Safari 11.1 and 12.1 to fail to load the SDK.
* The minified bundle size has been reduced (4%).

## 0.1.9

* Fix `deviceorientation` and `devicemotion` deprecation warnings in Firefox browsers on desktop.
Expand Down
8 changes: 4 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ version=$(node -p "require('./package.json').version")
# echo "Building version $version"

# Build site and library entry
esbuild src/entry/sdk.ts --bundle --outfile=build/bundle/sdk.js --format=esm --define:SDK_VERSION=\"$version\" --legal-comments=eof
esbuild src/entry/sdk.ts --bundle --outfile=build/bundle/sdk.js --format=esm --target=es6 --define:SDK_VERSION=\"$version\" --legal-comments=eof

esbuild src/entry/site.ts --bundle --outfile=build/bundle/site.js --define:SDK_VERSION=\"$version\" --legal-comments=eof
esbuild src/entry/recaptcha-site.ts --bundle --outfile=build/bundle/contrib/recaptcha-site.js --define:SDK_VERSION=\"$version\" --legal-comments=eof
esbuild src/entry/hcaptcha-site.ts --bundle --outfile=build/bundle/contrib/hcaptcha-site.js --define:SDK_VERSION=\"$version\" --legal-comments=eof
esbuild src/entry/site.ts --bundle --outfile=build/bundle/site.js --target=es6 --define:SDK_VERSION=\"$version\" --legal-comments=eof
esbuild src/entry/recaptcha-site.ts --bundle --outfile=build/bundle/contrib/recaptcha-site.js --target=es6 --define:SDK_VERSION=\"$version\" --legal-comments=eof
esbuild src/entry/hcaptcha-site.ts --bundle --outfile=build/bundle/contrib/hcaptcha-site.js --target=es6 --define:SDK_VERSION=\"$version\" --legal-comments=eof

# Babelize the site bundle

Expand Down
29 changes: 16 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@friendlycaptcha/sdk",
"version": "0.1.9",
"version": "0.1.10",
"description": "In-browser SDK for Friendly Captcha v2 (currently in preview only)",
"main": "dist/sdk.js",
"type": "module",
Expand Down Expand Up @@ -32,11 +32,11 @@
"@babel/cli": "^7.19.3",
"@babel/core": "^7.19.3",
"@babel/preset-env": "^7.19.3",
"idb-keyval": "^6.2.0",
"@microsoft/api-documenter": "^7.23.13",
"@microsoft/api-extractor": "^7.38.4",
"ava": "^6.0.0",
"esbuild": "^0.19.8",
"idb-keyval": "^6.2.0",
"indexeddbshim": "^10.1.0",
"license-check-and-add": "^4.0.5",
"prettier": "^3.0.0",
Expand Down
20 changes: 19 additions & 1 deletion sdktest/autotest/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ import (
func (r *TestRunner) PrintTestResult(tr *TestResult) {
timing := color.HiBlackString(fmt.Sprintf("(%s)", tr.Timing))

if errors.Is(tr.InternalError, context.DeadlineExceeded) {
fmt.Fprintf(
color.Output,
"%s %s %s %s\n",
color.HiRedString("ERROR Timeout exceeded"),
tr.Name,
timing,
color.YellowString(tr.Message),
)
return
}

switch tr.Status {
case "fail":
// In serve mode we display a link to click for quick debugging
Expand Down Expand Up @@ -52,6 +64,12 @@ func (r *TestRunner) PrintTestResult(tr *TestResult) {
case "skip":
fmt.Fprintf(color.Output, "%s %s %s\n", color.YellowString("SKIP"), color.HiBlackString(tr.Name), timing)
default: // Should never happen
fmt.Fprintf(color.Output, "%s %s %s\n", color.HiRedString("ERROR Invalid Test Result status: "), tr.Name, timing)
fmt.Fprintf(
color.Output,
"%s %s %s\n",
color.HiRedString("ERROR Invalid Test Result status: "),
tr.Name,
timing,
)
}
}
2 changes: 1 addition & 1 deletion sdktest/sdktest.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ autotest:
browser_exec_path: ""
headless: false
serve: false # Keep HTTP server alive (allows for links to failed tests).
timeout: "10000ms"
timeout: "30000ms"
concurrency: 2
2 changes: 1 addition & 1 deletion sdktest/sdktestlib/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SDKTestObject } from "./test";
import { SDKTestResult, SDKTestSuiteResult, TestFunction, TestOpts, TestStatus, TestSuiteEntry } from "./types";
import { SDKTestWidget, TestCaseResultWidget } from "./widget";

const DEFAULT_TIMEOUT = 5000;
const DEFAULT_TIMEOUT = 20_000;

export class SDKTestFramework {
private widget: SDKTestWidget;
Expand Down
1 change: 0 additions & 1 deletion src/compat/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export class CommonCompatSDK {
...el.dataset,
...params,
element: el,
sitekey: params?.sitekey,
language: this.params.hl || undefined,
});

Expand Down
2 changes: 1 addition & 1 deletion src/sdk/widgetHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class WidgetHandle {
*/
public destroy() {
this.isDestroyed = true;
this.hiddenFormEl?.remove();
this.hiddenFormEl && this.hiddenFormEl.remove();
this.hiddenFormEl = undefined;
this.setState({ response: ".DESTROYED", state: "destroyed" });
this._destroy();
Expand Down
12 changes: 8 additions & 4 deletions src/signals/collectStacktrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { mergeObject } from "../util/object";
import { windowPerformanceNow } from "../util/performance";

/**
Expand Down Expand Up @@ -148,10 +149,13 @@ export const takeRecords = (function () {
} catch (e) {}

try {
Object.defineProperty(target, prop, {
...descriptor,
[hasGetterOrSetter ? "get" : "value"]: newAccessor,
});
const newDescriptor = mergeObject({}, descriptor);
if (hasGetterOrSetter) {
newDescriptor.get = newAccessor;
} else {
newDescriptor.value = newAccessor;
}
Object.defineProperty(target, prop, newDescriptor);
origPatchMap.set(newAccessor, hasGetterOrSetter ? descriptor.get : descriptor.value);
} catch (e) {}
});
Expand Down

0 comments on commit 5f6f267

Please sign in to comment.