<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Capture Screenshot of Custom Visual with Button in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Capture-Screenshot-of-Custom-Visual-with-Button/m-p/4369415#M59117</link>
    <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I wanted to follow up and thank you for your earlier response to my question about using html2canvas in my Power BI custom visual!&lt;BR /&gt;&lt;BR /&gt;The error I am encountering is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Uncaught (in promise) SecurityError: Failed to read a named property 'document' from 'Window': Blocked a frame with origin "null" from accessing a cross-origin frame.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;From my understanding, this issue is happening because &lt;STRONG&gt;Power BI hosts custom visuals inside an iframe&lt;/STRONG&gt;. This is likely what’s causing the problem, as html2canvas tries to access the visual's content and is blocked due to cross-origin policies.&lt;BR /&gt;&lt;BR /&gt;Unfortunately, I'm not sure how to resolve this. Is there any&amp;nbsp; approach I can take to capture a screenshot of the visual? I’ve tried using the useCORS and allowTaint options in html2canvas, but that doesn’t seem to fix the issue.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If anyone has any insights or possible workarounds for dealing with this iframe sandboxing limitation, I would really appreciate your help!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 17 Jan 2025 14:56:07 GMT</pubDate>
    <dc:creator>Sytriox</dc:creator>
    <dc:date>2025-01-17T14:56:07Z</dc:date>
    <item>
      <title>Capture Screenshot of Custom Visual with Button</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Capture-Screenshot-of-Custom-Visual-with-Button/m-p/4368051#M59106</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am currently developing a custom visual for Power BI and I would like to add a feature that allows users to take a screenshot of the visual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The idea is to include a button within the visual, and when clicked, it would capture a screenshot of the visual, potentially using an external library like html2canvas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am aware that Power BI provides a context menu solution to copying it , but this approach won’t work for me due to limitations.&lt;/P&gt;&lt;P&gt;Given that Power BI hosts custom visuals within an iframe, is it possible to implement this functionality on the client side? Can html2canvas or a similar library be used to capture the visual's content?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate any insights or advice on how to achieve this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 20:55:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Capture-Screenshot-of-Custom-Visual-with-Button/m-p/4368051#M59106</guid>
      <dc:creator>Sytriox</dc:creator>
      <dc:date>2025-01-16T20:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: Capture Screenshot of Custom Visual with Button</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Capture-Screenshot-of-Custom-Visual-with-Button/m-p/4368591#M59110</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/465859"&gt;@Sytriox&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can refer the following links to get it:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://html2canvas.hertzen.com/documentation" target="_blank"&gt;About | html2canvas&lt;/A&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import * as d3 from "d3";
// Other imports as needed
import "html2canvas";

export class MyVisual implements IVisual {
    // Visual properties and constructor

    private captureButton: HTMLButtonElement;

    constructor(options: VisualConstructorOptions) {
        // Your constructor code

        this.captureButton = document.createElement("button");
        this.captureButton.innerText = "Capture Screenshot";
        this.captureButton.onclick = this.captureScreenshot.bind(this);
        options.element.appendChild(this.captureButton);
    }

    public update(options: VisualUpdateOptions) {
        // Your update code

        // Optionally append the button to the visual's DOM if it isn't already there
        if (!this.captureButton.parentElement) {
            options.element.appendChild(this.captureButton);
        }
    }

    private captureScreenshot() {
        html2canvas(document.querySelector('YOUR_VISUAL_ROOT_ELEMENT_SELECTOR')).then(canvas =&amp;gt; {
            const link = document.createElement('a');
            link.download = 'screenshot.png';
            link.href = canvas.toDataURL();
            link.click();
        });
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;In addition, you can raise a ticket in the Custom Visuals Development community for dedicated support.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcommunity.fabric.microsoft.com%2Ft5%2FCustom-Visuals-Development%2Fbd-p%2FCustomVisualsDevelopmentDiscussion&amp;amp;data=05%7C02%7Cv-yiruan%40microsoft.com%7Ceb6ac97633ad4cdcf08b08dd151ff084%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638689949132150054%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&amp;amp;sdata=oWpOwGfJzZZKDpqcTaUMaEmPx49SatNyOVhlHWTkT1c%3D&amp;amp;reserved=0" target="_blank" rel="noopener"&gt;Custom Visuals Development Discussion - Microsoft Fabric Community&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jan 2025 06:57:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Capture-Screenshot-of-Custom-Visual-with-Button/m-p/4368591#M59110</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-01-17T06:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Capture Screenshot of Custom Visual with Button</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Capture-Screenshot-of-Custom-Visual-with-Button/m-p/4369415#M59117</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I wanted to follow up and thank you for your earlier response to my question about using html2canvas in my Power BI custom visual!&lt;BR /&gt;&lt;BR /&gt;The error I am encountering is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Uncaught (in promise) SecurityError: Failed to read a named property 'document' from 'Window': Blocked a frame with origin "null" from accessing a cross-origin frame.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;From my understanding, this issue is happening because &lt;STRONG&gt;Power BI hosts custom visuals inside an iframe&lt;/STRONG&gt;. This is likely what’s causing the problem, as html2canvas tries to access the visual's content and is blocked due to cross-origin policies.&lt;BR /&gt;&lt;BR /&gt;Unfortunately, I'm not sure how to resolve this. Is there any&amp;nbsp; approach I can take to capture a screenshot of the visual? I’ve tried using the useCORS and allowTaint options in html2canvas, but that doesn’t seem to fix the issue.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If anyone has any insights or possible workarounds for dealing with this iframe sandboxing limitation, I would really appreciate your help!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 17 Jan 2025 14:56:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Capture-Screenshot-of-Custom-Visual-with-Button/m-p/4369415#M59117</guid>
      <dc:creator>Sytriox</dc:creator>
      <dc:date>2025-01-17T14:56:07Z</dc:date>
    </item>
  </channel>
</rss>

