Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yellow-adults-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tma.js/bridge": patch
---

Rework the `hasWebviewProxy` function considering that the passed value is more likely to be window object
1 change: 1 addition & 0 deletions packages/bridge/src/env/hasWebviewProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ it('should return true if passed object contains path property "TelegramWebviewP
expect(hasWebviewProxy({ TelegramWebviewProxy: {} })).toBe(false);
expect(hasWebviewProxy({ TelegramWebviewProxy: { postEvent: [] } })).toBe(false);
expect(hasWebviewProxy({
a: 'b',
TelegramWebviewProxy: {
postEvent: () => {
},
Expand Down
8 changes: 4 additions & 4 deletions packages/bridge/src/env/hasWebviewProxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { looseObject, function as fn, is } from 'valibot';
import * as v from 'valibot';

/**
* Returns true in case, passed value contains path `TelegramWebviewProxy.postEvent` property and
Expand All @@ -10,8 +10,8 @@ export function hasWebviewProxy<T>(value: T): value is T & {
postEvent: (...args: unknown[]) => unknown;
};
} {
return is(
looseObject({ TelegramWebviewProxy: looseObject({ postEvent: fn() }) }),
value,
return typeof value === 'object' && !!value && !Array.isArray(value) && v.is(
v.looseObject({ TelegramWebviewProxy: v.looseObject({ postEvent: v.function() }) }),
{ TelegramWebviewProxy: (value as Record<string, unknown>).TelegramWebviewProxy },
);
}
Loading