Load a local bitmap over file:// in easeljs - google-chrome

I'm trying to add a local jpg to my canvas using easeljs with the following code:
var bitmap = new createjs.Bitmap('img/gallery/1.jpg');
stage.addChild(bitmap);
This puts the image on the canvas. I then want to add an onclick event to the image:
var bitmap = new createjs.Bitmap('img/gallery/1.jpg');
bitmap.addEventListener("click", function(){
alert("CLICKED");
});
stage.addChild(bitmap);
This causes the following error:
Uncaught An error has occurred. This is most likely due to security restrictions on reading canvas pixel data with local or cross-domain images.
Obviously a cross origin type issue. I noticed the following in the easeljs docs:
Images loaded cross-origin will throw cross-origin security errors when interacted with using a mouse, using methods such as getObjectUnderPoint, or using filters, or caching. You can get around this by setting crossOrigin flags on your images before passing them to EaselJS, eg: img.crossOrigin="Anonymous";
I tried this (following the steps here http://developers.spilgames.com/wiki/Developer_Platform_-_Learning_center_-FAQ-_HTML5_API_CreateJS_cross-domain_error) and then got two errors:
Image from origin 'file://' has been blocked from loading by Cross-Origin Resource Sharing policy: Received an invalid response. Origin 'null' is therefore not allowed access.
Uncaught InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state.
As the project I'm building is a Cordova/Phonegap project which needs to be able to run offline, getting the images from a web server is not possible, as far as I can see the images must come over file://. Does anybody have any ideas of how I can get around this issue?

To prevent cross origin issues Chrome automatically blocks such images. You can run it in Firefox without causing the trouble.
In order to test these in chrome you have to run the file in local server like Apache tomcat.
Or use the running options run on server from Web storm like IDE.
If you don't have Web storm set up Apache tomcat server and copy your project folder in Apache tomcat/webapps folder. Now start the tomcat server, type http://localhost:8080/pathto your project folder in webapps.
ie if your project is in ../tomcat7/webapps/myproject/game.html
type http://localhost:8080/myproject/game.html

Create a another Chrome shortcut and add --disable-web-security to the /chrome.exe schortcut link. Restart chrome using this link.

Related

ERR_CERT_AUTHORITY_INVALID error in Chrome while using Overrides

I'm trying to test some features in a production environment, and to achieve this I'm using Google Chrome overrides, that basically allows you to substitute a remote file with a local file.
It sometimes works, but after a couple of reloads it stops working and all the requests start failing, receiving this error in console:
Pay attention: I'm not talking of the full page warning that you see when you access an untrusted website, which has the same error code. I'm talking about the error in console which makes the website unusable.
I say this because I tried googling the error and I only see articles about the warning, that you can easily skip. This is a different subject.
What I tried so far, without success is:
Start chrome with the --ignore-certificate-errors flag
Enabling the allow-insecure-localhost flag in chrome://flags
But they didn't help. How can I tell Chrome to ignore the (inexistent) certificate?
Thank you
Edit
I add an image of my override configuration:
to-override is my local folder. Then I just clicked on a file in the source tab and selected save for override. I found the file in my local folder and I changed it. Changes are applied the first time, but on refresh everything stops working and all the requests fail.
My Chrome version is
71.0.3578.98 - stable - 64 bit

Polymer serve and service worker

I am trying to get started on debugging my Polymer application. I have hand crafted it by copying what I think the PolymerCLI Polymer init does.
I am not sure what is loading service worker. The default one for development just does a console.info() call saying its been disabled for development.
When I use Polymer serve to serve my application on localhost: 8080, I get the console.info message, despite there being nowhere where I actually load the file service-worker.js . Because the application is much more complex (and I am trying to use http/2) I have my own node based server as well. When I run that and then fetch my application in the browser, service-worker.js does not get loaded and run.
What is Polymer serve doing to enable it?
It could be that a different application which used the same source (e.g. localhost:8080) registered and installed a service worker.
Open up the Application panel in Chrome Canary to inspect / delete the service worker.
If you can't access Chrome Canary, open chrome://serviceworker-internals, find the scope that matches your app, and click Unregister. There's also an option at the top of serviceworker-internals which lets you open a DevTools window and pause JS on the SW. Enable that option and you'll be able to see which SW is running.

Polymer Starter Kit - ERR_FILE_EXISTS when trying to enable service worker

I am trying to follow the instructions from here to enable offline support (Service worker) in my polymer starter kit clone.
However, after making the changes in gulpfile.js, index.html and elements.html, I keep getting the following error whenever I refresh the page.
Also if I change the throttling setting to offline in Chrome Developer Tools and refresh, the page comes back with the "Unable to connect to the Internet" message so clearly the caching isn't working.
Is there anything else that I need to do?
Update: Just decoded the url (i.e. http://localhost:5000/bower_components/platinum-sw/platinum-sw-register.html&clientsClaim=true&skipWaiting=true&version=1.0) in the error message and ran it in Chrome and got a 404 error. If I remove everything after .html then the file can be found though.
I was having the same issue and turned out it's because the platinum-sw-cache is set to disabled in the dev development, which means service worker will not work if you run
gulp serve
So to test the PSK offline, you need to call
gulp serve:dist
You can also ignore that ERR_FILE_EXISTS error as explained by #pirxpilot.

Executing Flashbuilder application results in Error 2148 Only local-with-filesystem and trusted local SWF files may access local resources

As the title implies i have problems making a very simple (actually an empty project) to run!
I always get the follwing error:
SecurityError: Error #2148: SWF file file:///C:/Users/Σάββας/Adobe Flash Builder 4/Test/bin-debug/Test.swf cannot access local resource file:///C:/Users/Σάββας/Adobe Flash Builder 4/Test/bin-debug/osmf_flex.4.0.0.13495.swf. Only local-with-filesystem and trusted local SWF files may access local resources.
at flash.net::URLStream/load()
at flash.net::URLLoader/load()
at mx.core::CrossDomainRSLItem/load()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\CrossDomainRSLItem.as:240]
at mx.core::RSLListLoader/loadNext()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\RSLListLoader.as:184]
at mx.core::RSLListLoader/load()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\RSLListLoader.as:156]
at mx.preloaders::Preloader/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\preloaders\Preloader.as:279]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:1925]
at mx.managers::SystemManager/initHandler()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2419]
Is there something i have done wrong? Ι also tried to debug (the empty application) with no success!!
I tried to set the Global Security Settings for the folders involved in developing to always allow but the result is the same!!
My problem is that i will not be able to debug the application which is of verrrryyyy annoying.
I 'm using Flashbuilder 4, FlexSDK4, Mozilla.
Any hint is appreciated!
This error occurs when you try to open an application that uses RSLs in the standalone player or in the browser by using the file system and not a server. It means that you are violating the security sandbox of Flash Player by trying to load file resources.
You must deploy your application and RSLs to a network location, and request the application with a network request so that Flash Player will load the RSL.
If you are testing the application locally, you can add the directory to your Player trust file to avoid this error.

Security Sandbox in AS3

What is a security sandbox violation, and how do I override it? I'm making a project in FlashDevelop, and today, it will not load external files, even though it had been previously. It gives the following output:
************* Security Sandbox Violation ********* Connection to
file:///C|/Documents%20and%20Settings/Kevin.PC885314341208/Desktop/Import%20.txt/StockData/1.txt
halted - not permitted from
file:///C|/Documents%20and%20Settings/Kevin.PC885314341208/Desktop/Import%20.txt/import.swf
I hope this isn't a serious problem.
Thanks for any help.
The error message you posted shows that you're trying to load a local file from a local swf. This error can be fixed for your scenario.
In FlashDevelop, set "Use Network Services" to false (Project Properties -> Compiler Options tab). This will prevent your swf from accessing the internet but will let you load local files. Setting it to true will allow internet access but not access to local files.
In Flash, the setting is under "Publish Settings", Flash tab. It's called "Local playback security" and the settings are "Access local files only" or "Access network only". It's the same setting as in FlashDevelop, just a different name.
You can also switch the "Use Network" flag of a swf file after publish/compile by using the Adobe's free+open Local Content Updater.
You're loading a local file, something that's not permitted. However, as you're developing this you can of course allow this.
Add your project folder to the trusted locations: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html
Edit: I might add that if you run it with networking disabled it will work (this is for development purposes). This happens for example when you run it from the Flash IDE, which would explain why it may have worked before?
You cannot load desktop files when you try to run a SWF through a web browser. Flash does not give you access to the local hard drive, as that would be a major security issue. You will have to place those files on a server somewhere and pass Flash a direct URL.
OK. I got it to work by publishing it using FlashDevelop's built in flashplayer (I don't know how to describe it better). I wasn't able to use the security settings that Antti suggested though.