I'd like to shorten my URL's using the Firebase Dynamic Link shortener. I followed the Rest API reference and the code seems to check out:
const url ="https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=MY_API_KEY";
this.request = new XMLHttpRequest();
this.request.open("GET", url, true);
this.request.setRequestHeader("Content-Type", "application/json");
this.request.setRequestHeader("Access-Control-Allow-Origin", "*");
const parameters = {
"longDynamicLink": encodeURIComponent(window.location)
};
this.request.onreadystatechange = this.updateLink;
this.request.send(parameters);
But when I execute this code, I get a CORS error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=MY_API_KEY. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
I can't seem to find a setting where I can enable Cross Origin Requests. Anyone who can tell me how to use Firebase Dynamic Links from the browser?