Skip to content

Commit 986156e

Browse files
committed
docs: screenshot api
1 parent 762dd11 commit 986156e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/phoenix/shell.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,17 @@ Phoenix.app = {
881881
* - A jQuery selector string (must match exactly one element)
882882
* - Omit to capture the full page
883883
* @returns {Promise<Uint8Array>} PNG image data
884+
* @example <caption>Capture a specific rectangle</caption>
885+
* const bytes = await Phoenix.app.screenShotBinary({
886+
* x: 100, y: 100, width: 400, height: 300
887+
* });
888+
* @example <caption>Capture a DOM element</caption>
889+
* const element = document.getElementById("preview");
890+
* const bytes = await Phoenix.app.screenShotBinary(element);
891+
* @example <caption>Capture using a selector</caption>
892+
* const bytes = await Phoenix.app.screenShotBinary("#preview");
893+
* @example <caption>Capture the full page</caption>
894+
* const bytes = await Phoenix.app.screenShotBinary();
884895
*/
885896
screenShotBinary: function (rectOrNodeOrSelector) {
886897
return _capturePageBinary(rectOrNodeOrSelector);
@@ -893,6 +904,14 @@ Phoenix.app = {
893904
* - A jQuery selector string (must match exactly one element)
894905
* - Omit to capture the full page
895906
* @returns {Promise<Blob>} PNG Blob with type "image/png"
907+
* @example <caption>Display in an image element</caption>
908+
* const blob = await Phoenix.app.screenShotToBlob("#preview");
909+
* const url = URL.createObjectURL(blob);
910+
* document.getElementById("imgOutput").src = url;
911+
* @example <caption>Draw to a canvas</caption>
912+
* const blob = await Phoenix.app.screenShotToBlob();
913+
* const bitmap = await createImageBitmap(blob);
914+
* ctx.drawImage(bitmap, 0, 0);
896915
*/
897916
screenShotToBlob: async function (rectOrNodeOrSelector) {
898917
const bytes = await _capturePageBinary(rectOrNodeOrSelector);
@@ -907,6 +926,14 @@ Phoenix.app = {
907926
* - A jQuery selector string (must match exactly one element)
908927
* - Omit to capture the full page
909928
* @returns {Promise<void>}
929+
* @throws {Error} If filePathToSave is not a non-empty string
930+
* @example <caption>Save the full page</caption>
931+
* await Phoenix.app.screenShotToPNGFile("/project/output/screenshot.png");
932+
* @example <caption>Save a specific element</caption>
933+
* await Phoenix.app.screenShotToPNGFile(
934+
* "/project/output/preview.png",
935+
* "#preview"
936+
* );
910937
*/
911938
screenShotToPNGFile: async function (filePathToSave, rectOrNodeOrSelector) {
912939
if (!filePathToSave || typeof filePathToSave !== 'string') {

0 commit comments

Comments
 (0)