我正在Android Studio应用程序中实现通知功能。我正在使用Firebase JS版本。运行命令from selenium import webdriver
#javaScript function to drag and drop
simulateFunction = str("function simulateDragDrop(sourceNode, destinationNode) {\n" +
" var EVENT_TYPES = {\n" +
" DRAG_END: 'dragend',\n" +
" DRAG_START: 'dragstart',\n" +
" DROP: 'drop'\n" +
" }\n" +
"\n" +
" function createCustomEvent(type) {\n" +
" var event = new CustomEvent(\"CustomEvent\")\n" +
" event.initCustomEvent(type, true, true, null)\n" +
" event.dataTransfer = {\n" +
" data: {\n" +
" },\n" +
" setData: function(type, val) {\n" +
" this.data[type] = val\n" +
" },\n" +
" getData: function(type) {\n" +
" return this.data[type]\n" +
" }\n" +
" }\n" +
" return event\n" +
" }\n" +
"\n" +
" function dispatchEvent(node, type, event) {\n" +
" if (node.dispatchEvent) {\n" +
" return node.dispatchEvent(event)\n" +
" }\n" +
" if (node.fireEvent) {\n" +
" return node.fireEvent(\"on\" + type, event)\n" +
" }\n" +
" }\n" +
"\n" +
" var event = createCustomEvent(EVENT_TYPES.DRAG_START)\n" +
" dispatchEvent(sourceNode, EVENT_TYPES.DRAG_START, event)\n" +
"\n" +
" var dropEvent = createCustomEvent(EVENT_TYPES.DROP)\n" +
" dropEvent.dataTransfer = event.dataTransfer\n" +
" dispatchEvent(destinationNode, EVENT_TYPES.DROP, dropEvent)\n" +
"\n" +
" var dragEndEvent = createCustomEvent(EVENT_TYPES.DRAG_END)\n" +
" dragEndEvent.dataTransfer = event.dataTransfer\n" +
" dispatchEvent(sourceNode, EVENT_TYPES.DRAG_END, dragEndEvent)\n" +
"}; ")
### Start Process
# create a new Chrome session
driver = webdriver.Chrome()
driver.implicitly_wait(30)
driver.maximize_window()
driver.get('https://www.w3schools.com/html/html5_draganddrop.asp')
#call javascript dragdrop function
#here, drag1 and div2 are the page-specific IDs of the item to drag and the place to drop it, respectively.
driver.execute_script(simulateFunction + "var toDrag =document.getElementById('drag1'); var toDrop = document.getElementById('div2'); simulateDragDrop(toDrag, toDrop);")
时,出现错误firebase deploy
。
我尝试使用以下方式更新Firebase工具:
Error occurred while parsing your function triggers
这是我的npm install -g firebase-tools@latest
index.js
我正在尝试将功能上传到我的Firebase控制台。但是,输入命令'use strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification =functions.database.ref('/Notifications/{receiver_user_id}/{notification_id}')
.onWrite((data, context) =>
{
const receiver_user_id = context.params.receiver_user_id;
const notification_id = context.params.notification_id;
console.log('We have a notification to send to :' , receiver_user_id);
if (!data.after.val())
{
console.log('A notification has been deleted :' , notification_id);
return null;
}
const DeviceToken = admin.database().ref(`/Users/${receiver_user_id}/device_token`).once('value');
return DeviceToken.then(result =>
{
const token_id = result.val();
const payload =
{
notification:
{
title: "New Chat Request",
body: `you have a new Chat Request, Please Check.`,
icon: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload)
.then(response =>
{
console.log('This was a notification feature.');
});
});
});
firebase deploy
我的节点版本为Error: Error occurred while parsing your function triggers.
C:\Users\shanj\Desktop\Notification\functions\index.js:4
cont admin = require('firebase-admin');
^^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at C:\Users\shanj\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:15:15
at Object.<anonymous> (C:\Users\shanj\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:53:3)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
,npm版本为v12.6.0
。
答案 0 :(得分:0)
您保存了源文件吗?错误是说您的代码行是这样的:
cont admin = require('firebase-admin');
请注意,它是“ cont”而不是“ const”。 “ cont”不是有效的JavaScript关键字。您的代码显示为“ const”,因此也许您只是在部署之前没有保存文件。