NOTE: There is no issue here, The issue was with my functions.json script file location. It was pointing to an old script file. The minute I pointed to a new one, it started working.
I am not sure why this is happening, I have a try-catch block and the function never hits the catch block but the image I am trying upload never shows up in the container.
I am new to NODEJS. Since I cant achieve the same thing using C# functions, I decided to write it in the node.
Problem: Azure function Service bus topic trigger, take the message payload and grabs a screenshot of the page using puppeteer. The output from the buffer is in form of the buffer, I am trying to upload this to Azure storage blob.
import { AzureFunction, Context } from "@azure/functions";
import { ServiceBusMessage } from "@azure/service-bus";
import * as puppeteer from 'puppeteer';
import * as BlobServiceClient from "azure-storage";
import { Readable } from 'stream';
const serviceBusTopicTrigger: AzureFunction = async function (context: Context, mySbMsg: ServiceBusMessage): Promise<void> {
try {
const promotionId = context.bindingData.userProperties.promotionId;
context.log('Player Screen Grabber ServiceBus topic trigger function processing message started', promotionId);
const playerURL = process.env['playerURL'] + promotionId + '/';
let browser = await puppeteer.launch({ headless: true });
let page = await browser.newPage();
await page.goto(playerURL, { waitUntil: 'networkidle2' });
await page.setViewport({ width: 1920, height: 1080 });
const screenshotBuffer = await page.screenshot({
encoding: 'binary'
});
await page.close();
await browser.close();
const newPlayerScreenShotStream = new Readable({
read() {
this.push(screenshotBuffer);
},
});
var fileName = promotionId + ".png";
context.bindings.fileName = fileName;
context.bindings.storage = screenshotBuffer;
context.done();
context.log('Player Screen Grabber ServiceBus topic trigger function processing message ended', promotionId);
}
catch (error) {
throw error;
}
};





