Add unknown to msg type in action triggers

Add errors to post msg saga
This commit is contained in:
Rimil Dey 2022-04-21 10:25:20 +05:30
parent 1e4d39b4ae
commit fdb2c6e805
3 changed files with 15 additions and 4 deletions

View File

@ -171,7 +171,7 @@ export type ConfirmationModal = {
export type PostMessageDescription = {
type: ActionTriggerType.POST_MESSAGE;
payload: {
message: any;
message: unknown;
targetOrigin: string;
};
};

View File

@ -1,6 +1,9 @@
import { spawn } from "redux-saga/effects";
import { PostMessageDescription } from "../../entities/DataTree/actionTriggers";
import { logActionExecutionError } from "sagas/ActionExecution/errorUtils";
import {
logActionExecutionError,
TriggerFailureError,
} from "sagas/ActionExecution/errorUtils";
import { TriggerMeta } from "./ActionExecutionSagas";
export function* postMessageSaga(
@ -16,7 +19,15 @@ export function* executePostMessage(
) {
const { message, targetOrigin } = payload;
try {
window.parent.postMessage(message, targetOrigin, undefined);
if (targetOrigin === "*") {
throw new TriggerFailureError(
"Please enter a valid url as targetOrigin. Failing to provide a specific target discloses the data you send to any interested malicious site.",
);
} else if (!message) {
throw new TriggerFailureError("Please enter a message.");
} else {
window.parent.postMessage(message, targetOrigin, undefined);
}
} catch (error) {
logActionExecutionError(
error.message,

View File

@ -673,7 +673,7 @@ export const GLOBAL_FUNCTIONS = {
postMessageToTargetWindow: {
"!doc":
"Establish cross-origin communication between Window objects/page and iframes",
"!type": "fn(message: any, targetOrigin: string, transfer: [any])",
"!type": "fn(message: unknown, targetOrigin: string, transfer: [any])",
},
};