You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So in safari extension I only have one file named script.js which is lilke background.js. It can send data to Swfit code and display them.
letsfConn={asyncrest(url,{logErrors =true, method ="GET", api ="normal", body =undefined, bodyType ="json", headers ={}, progressHandler =null}={}){try{constsidRegex=/sid=(.*?);/;constsidMatch=document.cookie.match(sidRegex);constsessionId=sidMatch ? sidMatch[1] : null;consthostname=window.location.hostname;letxhr=newXMLHttpRequest();url+=(url.includes("?") ? "&" : "?")+"cache="+Math.random();xhr.open(method,"https://"+hostname+url,true);console.log("https://"+hostname+url+" sid: "+sessionId);xhr.setRequestHeader("Accept","application/json; charset=UTF-8");if(api=="bulk"){xhr.setRequestHeader("X-SFDC-Session",sessionId);}elseif(api=="normal"){xhr.setRequestHeader("Authorization","Bearer "+sessionId);}else{thrownewError("Unknown api");}if(body!==undefined){if(bodyType=="json"){body=JSON.stringify(body);xhr.setRequestHeader("Content-Type","application/json; charset=UTF-8");}elseif(bodyType=="raw"){// Do nothing}else{thrownewError("Unknown bodyType");}}xhr.responseType="json";console.log("before promise");awaitnewPromise((resolve,reject)=>{if(progressHandler){progressHandler.abort=()=>{leterr=newError("The request was aborted.");err.name="AbortError";reject(err);xhr.abort();};}xhr.onreadystatechange=()=>{if(xhr.readyState==4){resolve();}};console.log("sending xhr");xhr.send(body);});if(xhr.status>=200&&xhr.status<300){console.log("good, returning ");console.log(xhr);console.log(xhr.response);returnxhr.response;}elseif(xhr.status==0){if(!logErrors){console.error("Received no response from Salesforce REST API",xhr);}leterr=newError();err.name="SalesforceRestError";err.message="Network error, offline or timeout";throwerr;}else{if(!logErrors){console.error("Received error response from Salesforce REST API",xhr);}leterr=newError();err.name="SalesforceRestError";err.detail=xhr.response;try{err.message=err.detail.map(err=>`${err.errorCode}: ${err.message}${err.fields&&err.fields.length>0 ? ` [${err.fields.join(", ")}]` : ""}`).join("\n");}catch(ex){err.message=JSON.stringify(xhr.response);}if(!err.message){err.message="HTTP error "+xhr.status+" "+xhr.statusText;}throwerr;}}catch(e){console.log(e);}}};constfullQuerySelect="select Id, Name FROM User LIMIT 1";console.log("calling");sfConn.rest("/services/data/v56.0"+"/query?q="+encodeURIComponent(fullQuerySelect),{logErrors: false}).then(res=>{for(letrecordofres.records){console.log(record.Name);}}).catch(()=>{//Swallow this exception since it is likely due to missing standard attributes on the record - i.e. an invalid query.console.log("caught error");});
This is executed in my sandbox hostname ends with "lightning.force.com", however I observed the request will be redirected to another ends with "my.salesforce.com". I suspect this is why it blocks my request. Anyone can directly copy this code and run in chrome console.
Could anyone shed some light, please?
First image is the successful request sent by inspector extension on chrome.
Second is my code executed on chrome console
The text was updated successfully, but these errors were encountered:
According to this article, it is because my request is generated from lightning.force.com which is the same as LWC. The api hostname ends with salesforce.com. And since they are not the same origin hence the request fails. What I couldn't understand is why is Inspector capable of making calls from salesforce.com????? I didn't see any secret in the inspector.js code.
So in safari extension I only have one file named script.js which is lilke background.js. It can send data to Swfit code and display them.
This is executed in my sandbox hostname ends with "lightning.force.com", however I observed the request will be redirected to another ends with "my.salesforce.com". I suspect this is why it blocks my request. Anyone can directly copy this code and run in chrome console.
Could anyone shed some light, please?
First image is the successful request sent by inspector extension on chrome.
Second is my code executed on chrome console
The text was updated successfully, but these errors were encountered: