Chrome Security Issue with Image Rendering in Three.js Canvas

Having trouble loading a canvas-generated image in Chrome (it works fine in Firefox).

"Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at blob:*** could not be loaded.

I've managed to make it work with other images, but the problem arises when I use an SVG for HTML-rendered text. For example, check out this link.

The usual security measures like img.crossOrigin = "*" or

THREE.ImageUtils.crossOrigin = '*'
are not solving the issue. Any suggestions on how to resolve this?

Here is the code snippet:

$("body").append('<canvas id="canvas" style="border:2px solid black;" width="200" height="200"></canvas>');
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');

var data = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">' +
           '<foreignObject width="100%" height="100%">' +
           '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:40px">' +
            html +
           '</div>' +
           '</foreignObject>' +
           '</svg>';

var DOMURL = window.URL || window.webkitURL || window;

var img = new Image();
var svg = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
svg.crossOrigin = "*";
var url = DOMURL.createObjectURL(svg);

img.onload = function () {
  ctx.drawImage(img, 0, 0);

  THREE.ImageUtils.crossOrigin = '*';
  var texture = THREE.ImageUtils.loadTexture(url);
  texture.needsUpdate = true;


    var posterText = new THREE.Mesh(
    new THREE.BoxGeometry(img.naturalWidth, img.naturalHeight,1),
        new THREE.MeshPhongMaterial({
            map: texture,
            transparent: true
        })
    );  


    DOMURL.revokeObjectURL(url);
};

img.crossOrigin = "*";
img.src = url;

Answer №1

Hey Erik, appreciate your help. It looks like we'll have to wait for this issue to be resolved before moving forward. In the meantime, I'll use html2canvas instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sharing CSS styles among multiple single-page applications (SPAs) developed using the React

I am currently working on multiple micro SPAs that exist independently within an Express environment. I am facing a challenge with importing a global CSS file that is located outside of the apps, as it is not being recognized. The use of @import url(asset ...

reactjs implementation of a virtualized list

Recently, I stumbled upon the React-window library and found it to be incredibly useful. Intrigued by how it was built, I decided to try my hand at creating my own virtualized list. However, I encountered an issue where the list could only scroll up to it ...

Load as soon as the browser is launched

I have developed a unique button that utilizes JavaScript to display the server status through an API. However, I am facing an issue where the server status does not automatically load when the browser is opened for the first time. You need to manually cli ...

A guide to generating dynamic table headers using JSON in React

Looking to create a dynamic table with columns/headers in React based on a JSON array of objects. The data: example = [ { id: 0, city: 'New York', }, { id: 1, city: 'Paris', }, ] Currently, I'm iterating ...

Merging two separate observableArray into a single entity in knockout js

I am currently working on merging two distinct arrays into a general array and then connecting it using foreach. My View Model: self.cancelledItem1 = ko.computed(function () { return ko.utils.arrayFilter(self.items(), function (item) { ...

Invoking a function in a React component from another component

I am trying to implement a page with the structure shown below: const Upload = (props) => { return ( <BaseLayout> <ToolbarSelection /> <Box> <FileDropArea /> </ ...

Refreshing Information Iteratively

I am currently working on updating the rate field in the currency table using my nodejs controller. While everything runs smoothly in S3T / RoboMongo, I'm facing an issue where the update operation doesn't seem to execute inside the nodejs contr ...

Function being called by Intersection Observer at an inappropriate moment

After running the page, the intersection observer behaves exactly as desired. However, upon reloading the page, I am automatically taken back to the top of the page (which is expected). Strangely though, when the viewport interacts with the target elemen ...

Tips for creating a visual map using a URL

Here is a code snippet that I found: https://openlayers.org/workshop/en/vector/geojson.html The code requires a URL to a countries.json file, like this: url: './data/countries.json' When I run the code, only zoom in and zoom out buttons appear ...

Guide to retrieving objects in React.js

Struggling to extract a country from an online JSON file that I am currently fetching. I am attempting to streamline the process by creating a function to retrieve the country from the dataset and avoid repeating code. However, I am encountering difficulti ...

What is the best way to split two sets of radio buttons with the same name into distinct blocks in an HTML form?

For my project, I am working with two sets of radio buttons where the values are stored in a Database. Depending on another result in the HTML form, I need to display one set of radio buttons or the other. The issue arises when using the same name for all ...

Having difficulty converting a local variable into a global variable in JavaScript and Express

I am facing challenges trying to convert a local variable into a global variable while working with Express and Javascript. Below is my JavaScript code snippet: // Setting up Express and EJS const express = require("express"); const JSON = requi ...

Achieving Compatibility Between jQuery 3.6.0 and Node.js v12.16.1

Utilizing an online IDE known as Replit, I am working on node.js projects running on the node version: 12.16.1. However, my current challenge lies in attempting to make jQuery 3.6.0 compatible with this particular node.js version. Despite trying various me ...

"I'm having trouble resizing a GLTF model in Three.js - any tips on how to make it work

Having some trouble resizing the mesh loaded as GLTF - it appears that only the root is being resized, not the child. How can I properly resize the mesh from its root to its child? Here's what I've attempted so far: loader.load('assets/a1-e ...

What's causing Angular to not display my CSS properly?

I am encountering an issue with the angular2-seed application. It seems unable to render my css when I place it in the index.html. index.html <!DOCTYPE html> <html lang="en"> <head> <base href="<%= APP_BASE %>"> < ...

Sorting and Uploading Images made Easy with Drag-and-Drop Functionality

Currently, I am developing a webpage and exploring the option of implementing a drag-and-drop image upload system that allows users to remove and sort images before uploading. I am seeking your opinion on this matter. I am concerned about potential issue ...

I have implemented the Angular "Date" filter, but I'm unsure about the meaning of this numerical value

The Angular tutorial showcases the date filter with the following example: {{ 1304375948024 | date }} --> May 2, 2011` How would you notate the expression 1304375948024? ...

Tips for displaying content in a stacked format when hovering, similar to a list item (<li>), using jquery/javascript

I am attempting to display different content on hover over text, specifically listing various HTTP error codes. My setup includes 3 icons and text that will reveal specific content based on the text hovered over: success error blocked Below is the JS cod ...

Importance of xpath:position and xpath:attribute

I'm currently developing a recording tool using JavaScript that is comparable to Selenium. When it comes to Playback, I require the XPath position and its attributes (shown in the screenshot below from Selenium). Can anyone provide guidance on how to ...

Download files from Firebase storage to a user's device

I have a variety of files such as images, videos, and audio stored in my firebase storage. My goal is to provide users with the ability to download these files to their computers by clicking on a download button. After reviewing the firebase documentation ...