|
@@ -1,38 +1,58 @@
|
|
|
import { getBlockConnection, sendDebugCommand } from '../helper';
|
|
|
|
|
|
-function handleDialog({ data, outputs }) {
|
|
|
- const nextBlockId = getBlockConnection({ outputs });
|
|
|
+const overwriteDialog = (accept, promptText) => `
|
|
|
+ const realConfirm = window.confirm;
|
|
|
+ window.confirm = function() {
|
|
|
+ return ${accept};
|
|
|
+ };
|
|
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- if (BROWSER_TYPE !== 'chrome') {
|
|
|
- const error = new Error('log.messages.browser-not-supported');
|
|
|
- error.data = { browser: BROWSER_TYPE };
|
|
|
+ const realAlert = window.alert;
|
|
|
+ window.alert = function() {
|
|
|
+ return ${accept};
|
|
|
+ };
|
|
|
|
|
|
- reject(error);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!this.settings.debugMode) {
|
|
|
- const error = new Error('not-debug-mode');
|
|
|
- error.nextBlockId = nextBlockId;
|
|
|
+ const realPrompt = window.prompt;
|
|
|
+ window.prompt = function() {
|
|
|
+ return ${accept} ? "${promptText}" : null;
|
|
|
+ }
|
|
|
+`;
|
|
|
|
|
|
- reject(error);
|
|
|
- return;
|
|
|
- }
|
|
|
+function handleDialog({ data, outputs, id: blockId }) {
|
|
|
+ const nextBlockId = getBlockConnection({ outputs });
|
|
|
+
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ if (!this.settings.debugMode || BROWSER_TYPE !== 'chrome') {
|
|
|
+ const isScriptExist = this.preloadScripts.find(
|
|
|
+ ({ id }) => id === blockId
|
|
|
+ );
|
|
|
+
|
|
|
+ if (!isScriptExist) {
|
|
|
+ this.preloadScripts.push({
|
|
|
+ id: blockId,
|
|
|
+ isBlock: true,
|
|
|
+ name: 'javascript-code',
|
|
|
+ data: {
|
|
|
+ everyNewTab: true,
|
|
|
+ code: overwriteDialog(data.accept, data.promptText),
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.dialogParams = {
|
|
|
+ accept: data.accept,
|
|
|
+ promptText: data.promptText,
|
|
|
+ };
|
|
|
|
|
|
- this.dialogParams = {
|
|
|
- accept: data.accept,
|
|
|
- promptText: data.promptText,
|
|
|
- };
|
|
|
-
|
|
|
- const methodName = 'Page.javascriptDialogOpening';
|
|
|
- if (!this.engine.eventListeners[methodName]) {
|
|
|
- this.engine.on(methodName, () => {
|
|
|
- sendDebugCommand(
|
|
|
- this.activeTab.id,
|
|
|
- 'Page.handleJavaScriptDialog',
|
|
|
- this.dialogParams
|
|
|
- );
|
|
|
- });
|
|
|
+ const methodName = 'Page.javascriptDialogOpening';
|
|
|
+ if (!this.engine.eventListeners[methodName]) {
|
|
|
+ this.engine.on(methodName, () => {
|
|
|
+ sendDebugCommand(
|
|
|
+ this.activeTab.id,
|
|
|
+ 'Page.handleJavaScriptDialog',
|
|
|
+ this.dialogParams
|
|
|
+ );
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
resolve({
|