Arguments

The arguments passed to a background function must be serializable. They will be serialized using JSON.stringify upon enqueuing.

Here are some examples of serializable arguments:

myFunction(42)

If you pass a Date to your background function, JSON.stringify() will convert it to a string. So if your background function body expects a Date, it will fail. You’ll at least need to deserialize it yourself.

Here are some examples of non serializable arguments:

myFunction(new MyClass())

Result

The value returned by a background function should be a non-null value (void is permitted).

Please note that the execution result (return value) must be serializable. They will be serialized using JSON.stringify and stored after the execution is done.