<?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 CORS Error On CesiumJS Custom Visual in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/CORS-Error-On-CesiumJS-Custom-Visual/m-p/1198235#M24533</link>
    <description>&lt;P&gt;I'm trying to develop a CesiumJS custom visual, but I can't even get it to display the globe.&lt;/P&gt;&lt;P&gt;Every time I start it I get multiple CORS errors:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iGCarroll_0-1593698459130.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/304366i0180735F4CABA478/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iGCarroll_0-1593698459130.png" alt="iGCarroll_0-1593698459130.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anotación 2020-07-02 110723.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/304369i4D67FFC26CE16045/image-size/large?v=v2&amp;amp;px=999" role="button" title="Anotación 2020-07-02 110723.png" alt="Anotación 2020-07-02 110723.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anotación 2020-07-02 1107223.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/304382i4D466285DC6A6DFB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Anotación 2020-07-02 1107223.png" alt="Anotación 2020-07-02 1107223.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It seems like it tries to load some assets and create some workers, but &lt;EM&gt;app.powerbi.com&lt;/EM&gt; doesn't allow it. A lot of the different error messages follow this pattern:&lt;/P&gt;&lt;P&gt;"&lt;EM&gt;Access to XMLHttpRequest at &amp;lt;some CesiumJS file&amp;gt; from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;modified my webpack.config.js following all the steps in &lt;A href="https://cesium.com/docs/tutorials/cesium-and-webpack/" target="_self"&gt;here&lt;/A&gt; and it looks like this now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const config = require("../config.json");
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const cesiumSource = 'node_modules/cesium/Source';
const cesiumWorkers = '../Build/Cesium/Workers';

module.exports = {
    entry: {
        'visual.js': ['./src/visual.ts']
    },
    devtool: 'source-map',
    mode: "production",
    optimization: {
        minimizer: [
            new TerserPlugin({
                cache: true,
                parallel: true,
                sourceMap: true,
                terserOptions: {}
            })
        ],
        minimize: false,
        concatenateModules: false
    },
    performance: {
        maxEntrypointSize: 1024000,
        maxAssetSize: 1024000,
        hints: false
    },
    module: {
        rules: [
            {
                parser: {
                    amd: false
                }
            },
            {
                test: /\.json$/,
                loader: require.resolve('json-loader'),
                type: "javascript/auto"
            },
            {
                test: /(\.less)|(\.css)$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader
                    },
                    {
                        loader: require.resolve('css-loader')
                    },
                    {
                        loader: require.resolve('less-loader'),
                        options: {
                            paths: [path.resolve(__dirname, "..", 'node_modules')]
                        }
                    }
                ]
            },
            {
                test: /\.(woff|ttf|ico|woff2|jpg|jpeg|png|webp|gif|svg|eot)$/i,
                use: [
                    {
                        loader: require.resolve('base64-inline-loader')
                    }
                ]
            }
        ],
        unknownContextCritical: false
    },
    externals: {
        "powerbi-visuals-api": 'null',
        "fakeDefine": 'false',
        "corePowerbiObject": "Function('return this.powerbi')()",
        "realWindow": "Function('return this')()"
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.jsx', '.js', '.css'],
    },
    output: {
        path: null,
        publicPath: 'assets',
        filename: "[name]",
        sourcePrefix: ''
    },
    amd: {
        toUrlUndefined: true
    },
    node: {
        fs: 'empty'
    },
    devServer: {
        disableHostCheck: true,
        contentBase: null,
        compress: true,
        port: 8080,
        hot: false,
        inline: false,
        https: true,
        headers: {
            "access-control-allow-origin": "*",
            "cache-control": "public, max-age=0"
        }
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename: config.build.css,
            chunkFilename: "[id].css"
        }),
        new CopyWebpackPlugin([ { from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' } ]),
        new CopyWebpackPlugin([ { from: path.join(cesiumSource, 'Assets'), to: 'Assets' } ]),
        new CopyWebpackPlugin([ { from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' } ]),
        new webpack.DefinePlugin({
            CESIUM_BASE_URL: JSON.stringify('')
        })
    ]
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My visual.ts looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"use strict";

import "core-js/stable";
import "./../style/visual.less";
import powerbi from "powerbi-visuals-api";
import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
import IVisual = powerbi.extensibility.visual.IVisual;
import EnumerateVisualObjectInstancesOptions = powerbi.EnumerateVisualObjectInstancesOptions;
import VisualObjectInstance = powerbi.VisualObjectInstance;
import DataView = powerbi.DataView;
import VisualObjectInstanceEnumerationObject = powerbi.VisualObjectInstanceEnumerationObject;
import { VisualSettings } from "./settings";
import { Viewer, Ion } from 'cesium';
import "cesium/Build/Cesium/Widgets/widgets.css";

export class Visual implements IVisual {

    private target: HTMLElement;
    private container: HTMLDivElement;
    private settings: VisualSettings;

    constructor(options: VisualConstructorOptions) {
        this.target = options.element;
    }

    public update(options: VisualUpdateOptions) {
        let target = this.target;
        let container = this.container;
        let settings = this.settings;
        settings = Visual.parseSettings(options &amp;amp;&amp;amp; options.dataViews &amp;amp;&amp;amp; options.dataViews[0]);
        container = document.createElement("div");
        container.id = "cesiumContainer";
        target.appendChild(container);
        Ion.defaultAccessToken = '&amp;lt;myAccessToken&amp;gt;';
        var viewer = new Viewer('cesiumContainer');
    }

    private static parseSettings(dataView: DataView): VisualSettings {
        return &amp;lt;VisualSettings&amp;gt;VisualSettings.parse(dataView);
    }

    public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] | VisualObjectInstanceEnumerationObject {
        return VisualSettings.enumerateObjectInstances(this.settings || VisualSettings.getDefault(), options);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know a solution for this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jul 2020 14:24:54 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-07-02T14:24:54Z</dc:date>
    <item>
      <title>CORS Error On CesiumJS Custom Visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/CORS-Error-On-CesiumJS-Custom-Visual/m-p/1198235#M24533</link>
      <description>&lt;P&gt;I'm trying to develop a CesiumJS custom visual, but I can't even get it to display the globe.&lt;/P&gt;&lt;P&gt;Every time I start it I get multiple CORS errors:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iGCarroll_0-1593698459130.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/304366i0180735F4CABA478/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iGCarroll_0-1593698459130.png" alt="iGCarroll_0-1593698459130.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anotación 2020-07-02 110723.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/304369i4D67FFC26CE16045/image-size/large?v=v2&amp;amp;px=999" role="button" title="Anotación 2020-07-02 110723.png" alt="Anotación 2020-07-02 110723.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anotación 2020-07-02 1107223.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/304382i4D466285DC6A6DFB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Anotación 2020-07-02 1107223.png" alt="Anotación 2020-07-02 1107223.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It seems like it tries to load some assets and create some workers, but &lt;EM&gt;app.powerbi.com&lt;/EM&gt; doesn't allow it. A lot of the different error messages follow this pattern:&lt;/P&gt;&lt;P&gt;"&lt;EM&gt;Access to XMLHttpRequest at &amp;lt;some CesiumJS file&amp;gt; from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;modified my webpack.config.js following all the steps in &lt;A href="https://cesium.com/docs/tutorials/cesium-and-webpack/" target="_self"&gt;here&lt;/A&gt; and it looks like this now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const config = require("../config.json");
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const cesiumSource = 'node_modules/cesium/Source';
const cesiumWorkers = '../Build/Cesium/Workers';

module.exports = {
    entry: {
        'visual.js': ['./src/visual.ts']
    },
    devtool: 'source-map',
    mode: "production",
    optimization: {
        minimizer: [
            new TerserPlugin({
                cache: true,
                parallel: true,
                sourceMap: true,
                terserOptions: {}
            })
        ],
        minimize: false,
        concatenateModules: false
    },
    performance: {
        maxEntrypointSize: 1024000,
        maxAssetSize: 1024000,
        hints: false
    },
    module: {
        rules: [
            {
                parser: {
                    amd: false
                }
            },
            {
                test: /\.json$/,
                loader: require.resolve('json-loader'),
                type: "javascript/auto"
            },
            {
                test: /(\.less)|(\.css)$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader
                    },
                    {
                        loader: require.resolve('css-loader')
                    },
                    {
                        loader: require.resolve('less-loader'),
                        options: {
                            paths: [path.resolve(__dirname, "..", 'node_modules')]
                        }
                    }
                ]
            },
            {
                test: /\.(woff|ttf|ico|woff2|jpg|jpeg|png|webp|gif|svg|eot)$/i,
                use: [
                    {
                        loader: require.resolve('base64-inline-loader')
                    }
                ]
            }
        ],
        unknownContextCritical: false
    },
    externals: {
        "powerbi-visuals-api": 'null',
        "fakeDefine": 'false',
        "corePowerbiObject": "Function('return this.powerbi')()",
        "realWindow": "Function('return this')()"
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.jsx', '.js', '.css'],
    },
    output: {
        path: null,
        publicPath: 'assets',
        filename: "[name]",
        sourcePrefix: ''
    },
    amd: {
        toUrlUndefined: true
    },
    node: {
        fs: 'empty'
    },
    devServer: {
        disableHostCheck: true,
        contentBase: null,
        compress: true,
        port: 8080,
        hot: false,
        inline: false,
        https: true,
        headers: {
            "access-control-allow-origin": "*",
            "cache-control": "public, max-age=0"
        }
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename: config.build.css,
            chunkFilename: "[id].css"
        }),
        new CopyWebpackPlugin([ { from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' } ]),
        new CopyWebpackPlugin([ { from: path.join(cesiumSource, 'Assets'), to: 'Assets' } ]),
        new CopyWebpackPlugin([ { from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' } ]),
        new webpack.DefinePlugin({
            CESIUM_BASE_URL: JSON.stringify('')
        })
    ]
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My visual.ts looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"use strict";

import "core-js/stable";
import "./../style/visual.less";
import powerbi from "powerbi-visuals-api";
import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
import IVisual = powerbi.extensibility.visual.IVisual;
import EnumerateVisualObjectInstancesOptions = powerbi.EnumerateVisualObjectInstancesOptions;
import VisualObjectInstance = powerbi.VisualObjectInstance;
import DataView = powerbi.DataView;
import VisualObjectInstanceEnumerationObject = powerbi.VisualObjectInstanceEnumerationObject;
import { VisualSettings } from "./settings";
import { Viewer, Ion } from 'cesium';
import "cesium/Build/Cesium/Widgets/widgets.css";

export class Visual implements IVisual {

    private target: HTMLElement;
    private container: HTMLDivElement;
    private settings: VisualSettings;

    constructor(options: VisualConstructorOptions) {
        this.target = options.element;
    }

    public update(options: VisualUpdateOptions) {
        let target = this.target;
        let container = this.container;
        let settings = this.settings;
        settings = Visual.parseSettings(options &amp;amp;&amp;amp; options.dataViews &amp;amp;&amp;amp; options.dataViews[0]);
        container = document.createElement("div");
        container.id = "cesiumContainer";
        target.appendChild(container);
        Ion.defaultAccessToken = '&amp;lt;myAccessToken&amp;gt;';
        var viewer = new Viewer('cesiumContainer');
    }

    private static parseSettings(dataView: DataView): VisualSettings {
        return &amp;lt;VisualSettings&amp;gt;VisualSettings.parse(dataView);
    }

    public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] | VisualObjectInstanceEnumerationObject {
        return VisualSettings.enumerateObjectInstances(this.settings || VisualSettings.getDefault(), options);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know a solution for this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 14:24:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/CORS-Error-On-CesiumJS-Custom-Visual/m-p/1198235#M24533</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-07-02T14:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: CORS Error On CesiumJS Custom Visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/CORS-Error-On-CesiumJS-Custom-Visual/m-p/1198743#M24549</link>
      <description>&lt;P&gt;Hi @Anonymous&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;I'm not sure if I can solve this 100% for you, but might be able to provide some clarification or further ideas. I've previously attempted to use workers in a custom visual and it's... tricky.&lt;/P&gt;
&lt;P&gt;CORS errors in a visual are typically caused by the fact that the visual is hosted in a sandboxed iframe with &lt;FONT face="courier new,courier"&gt;allow-scripts&lt;/FONT&gt; as the only permission, which means that the domain has been removed from the visual's hosting iframe. So if you need to load remote dependencies and the remote server does not allow requests from a &lt;FONT face="courier new,courier"&gt;null&lt;/FONT&gt; origin, then there's not much you can do here, unless CesiumJS can relax this restriction from their end.&lt;/P&gt;
&lt;P&gt;Regarding Webpack customisation, I can't tell from the supplied if you're using &lt;A href="https://github.com/microsoft/powerbi-visuals-webpack-plugin" target="_self"&gt;powerbi-visuals-webpack-plugin&lt;/A&gt; or not in your project. If not, then trying to supply an overridden webpack configuration typically doesn't work as the SDK tools will always use the one local to the installed &lt;FONT face="courier new,courier"&gt;powerbi-visuals-tools&lt;/FONT&gt; package.&lt;/P&gt;
&lt;P&gt;If you have done this, it might be better to contact &lt;A href="mailto:pbicvsupport@microsoft.com" target="_blank"&gt;pbicvsupport@microsoft.com&lt;/A&gt; with further questions and your code, and the team may be able to provide you with targeted help on this one (they typically don't look at the forums, unfortunately &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; ). If you do get a resolution back under this channel, I'd love to know how you get on with this one - CesiumJS looks pretty cool!&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 19:44:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/CORS-Error-On-CesiumJS-Custom-Visual/m-p/1198743#M24549</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2020-07-02T19:44:44Z</dc:date>
    </item>
  </channel>
</rss>

