event.data:
{"id":2,"result":{"result":{"type":"object","subtype":"promise","className":"Promise","description":"Promise","objectId":"{\"injectedScriptId\":1,\"id\":1}"}}}
In the code you see where i show a message in MM5 and it does show the count of albums and the names of the albums appear in the message. Yeah!
How can i get the promised list of albums for processing in NodeJS?
Code: Select all
const WebSocket = require('ws');
var ws = new WebSocket("ws://localhost:9222/devtools/page/0A34A500F331A35BD411032547B65F05")
var exp =
" \
var sql = 'SELECT * FROM ALBUMS WHERE Artist = \"B.B. King\"'; \
var intCount = 0; \
var strMsg; \
\
function showMessage(msgToShow) { \
window.whenReady(() => {uitools.toastMessage.show(msgToShow, {disableUndo: true});}); \
} \
\
async function getAlbums() { \
await app.db.getQueryResultAsync(sql) \
.then(function (res) {while (!res.eof) {intCount++; strMsg = strMsg + res.fieldByName('Album'); res.next();}}) \
.then(function () {showMessage(\"strMsg:\" + intCount + ', ' + strMsg)}) \
} \
\
getAlbums(); \
";
console.log("exp:", "\n", exp);
var request = {
id: 2,
method: 'Runtime.evaluate',
params: {
expression:exp
}
}
ws.addEventListener('open', function (event) {
console.log("request expression:", "\n", request.params.expression, "\n\n");
ws.send(JSON.stringify(request));
});
ws.addEventListener('message', function (event) {
console.log("message=>", "\n", event.data, "\n\n");
console.log("event.data:", "\n", event.data, "\n\n");
var msg = JSON.parse(event.data);
console.log("msg (parsed json):", "\n", msg, "\n\n");
var result = msg.result.result;
console.log("result:", "\n", result, "\n\n");
var type = result.type;
console.log("type:", "\n", type, "\n\n");
if (type == "string") {
var value = result.value;
console.log("value:", "\n", value, "\n\n");
} else if (type == "object") {
var objectId = result.objectId;
console.log("objectId:", "\n", JSON.parse(objectId), "\n\n");
}
});
ws.addEventListener('error', function (event) {
console.log("error=>", "\n", event.data, "\n\n");
console.log("event.data:", "\n", event.data, "\n\n");
});