getPixels for an artboard selection

I currently have this code working for a document or layer selection, but when I try to use artboard layer id, I get an error

Unsupported layer type

I’m likely overlooking a step to get this to work. I tried sourceBounds to what I thought was the right dimensions, but it only returns a white background? Am I using the wrong sourceBounds or is this just not possible for artboards?

import { AdobeLayer } from "./types";

const photoshop = require("photoshop");
const { batchPlay } = require("photoshop").action;
const app = photoshop.app;
const imaging = photoshop.imaging;
const executeAsModal = photoshop.core.executeAsModal;
const kSRGBProfile = "sRGB IEC61966-2.1";

const thumbnailHeight = 150;

interface PixelOptions {
  documentID: number;
  layerID?: number;
  targetSize: { height: number };
  componentSize: -1 | 8 | 16 | 32;
  applyAlpha: boolean;
  colorProfile: string;
  sourceBounds?: { left: number; top: number; right: number; bottom: number };
}

export async function getImageThumbnail(activeLayer: AdobeLayer | undefined): Promise<string> {
  let targetDocument = app.activeDocument;
  if (targetDocument === undefined) {
    throw new Error("No open document");
  }

  const options: PixelOptions = {
    documentID: targetDocument.id,
    targetSize: { height: thumbnailHeight },
    componentSize: 8,
    applyAlpha: true,
    colorProfile: kSRGBProfile,
  };

  console.log("getImageThumbnail", activeLayer);
  if (activeLayer !== undefined) {
    options["layerID"] = activeLayer.id;
  }

  const pixels = await executeAsModal(async () => {
    return await imaging.getPixels(options);
  });

  let jpegData = await imaging.encodeImageData({
    imageData: pixels.imageData,
    base64: true,
  });

  const dataUrl = "data:image/jpeg;base64," + jpegData;
  pixels.imageData.dispose();
  return dataUrl;
}

An Artboard is technically a layer group which is why it is unsupported. In the future, we may be able to engage the compositor to give us the pixels that are contained therein.

For now, you’ll have to do a full document request where the sourceBounds matches the area of the document that comprises the Artboard in question.