function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Florian.GümbelFlorian.Gümbel 

LockerService causes error in window.crypto.getRandomValues()

Hi there,

I'm working on react modules for lightning components.
Some of my modules uses the window.crypt api.

The fact that LockerService encapsulates every compontent to have their own window etc. it seems that there is something going wrong:

This is my test js controller code:
({
	init : function(component, event, helper) {
                
		 console.log(window.crypto.getRandomValues(new window.Uint8Array(16)));
        
    }
})
This will thorw the following error:
This page has an error. You might just need to refresh it.
Error during init [Action failed: c:reactTest$controller$init [Failed to execute 'getRandomValues' on 'Crypto': parameter 1 is not of type 'ArrayBufferView'.]]

The react component uses the code in a simliar way.

It seems that the Uint8Array loses the binding (however) to the ArrayBufferView interface that the first argument needs to implement.

Any ideas to solve this?

Thank in advance!
 
Lokesh KumarLokesh Kumar
deativate locker service and try fope it will help 
Florian.GümbelFlorian.Gümbel
Thanks, but this is not my intention. Due LockerService will be activated on 14. June by default I'd like to work with it right now. It would not help to implement components with react or something else that are working without locker service even they will crash after activation.
Lokesh KumarLokesh Kumar
Try using like below 
 
({
	init : function(component, event, helper) {
               var byteArray = new Uint8Array(16);          
		 console.log(window.crypto.getRandomValues(byteArray));
        
    }
})

 
Florian.GümbelFlorian.Gümbel
Thanks for your answer, but your code snippet evaluates to the same functionality as my example. Referring only to Uint8Array would be the same as referring to window.Uint8Array.

Might be a real problem in the LockerService implementation :(