Skip to content

Commit

Permalink
Support .mil domains (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
tprouvot authored Oct 17, 2023
1 parent 35ce6b3 commit 172cee2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
16 changes: 15 additions & 1 deletion addon/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,21 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (sessionCookie) {
sendResponse(sessionCookie.domain);
} else {
sendResponse(null);
chrome.cookies.getAll({name: "sid", domain: "salesforce.mil", secure: true, storeId: sender.tab.cookieStoreId}, cookies => {
sessionCookie = cookies.find(c => c.value.startsWith(orgId + "!"));
if (sessionCookie) {
sendResponse(sessionCookie.domain);
} else {
chrome.cookies.getAll({name: "sid", domain: "cloudforce.mil", secure: true, storeId: sender.tab.cookieStoreId}, cookies => {
sessionCookie = cookies.find(c => c.value.startsWith(orgId + "!"));
if (sessionCookie) {
sendResponse(sessionCookie.domain);
} else {
sendResponse(null);
}
});
}
});
}
});
}
Expand Down
5 changes: 2 additions & 3 deletions addon/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
// sfdcBody = normal Salesforce page
// ApexCSIPage = Developer Console
// auraLoadingBox = Lightning / Salesforce1
// location.host.endsWith("visualforce.com") = Visualforce page
if (document.querySelector("body.sfdcBody, body.ApexCSIPage, #auraLoadingBox") || location.host.endsWith("visualforce.com")) {
// We are in a Salesforce org
chrome.runtime.sendMessage({ message: "getSfHost", url: location.href }, sfHost => {
chrome.runtime.sendMessage({message: "getSfHost", url: location.href}, sfHost => {
if (sfHost) {
initButton(sfHost, false);
}
Expand Down Expand Up @@ -120,7 +119,7 @@ function initButton(sfHost, inInspector) {
});
rootEl.appendChild(popupEl);
function openPopup() {
popupEl.contentWindow.postMessage({ insextUpdateRecordId: true, locationHref: location.href }, "*");
popupEl.contentWindow.postMessage({insextUpdateRecordId: true, locationHref: location.href}, "*");
rootEl.classList.add("insext-active");
// These event listeners are only enabled when the popup is active to avoid interfering with Salesforce when not using the inspector
addEventListener("click", outsidePopupClick);
Expand Down
16 changes: 14 additions & 2 deletions addon/manifest-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
"https://*.salesforce.com/*",
"https://*.force.com/*",
"https://*.cloudforce.com/*",
"https://*.visualforce.com/*"
"https://*.visualforce.com/*",
"https://*.salesforce.mil/*",
"https://*.force.mil/*",
"https://*.cloudforce.mil/*",
"https://*.visualforce.mil/*",
"https://*.crmforce.mil/*"
],
"content_scripts": [
{
Expand All @@ -27,7 +32,14 @@
"https://*.vf.force.com/*",
"https://*.lightning.force.com/*",
"https://*.cloudforce.com/*",
"https://*.visualforce.com/*"
"https://*.visualforce.com/*",
"https://*.salesforce.mil/*",
"https://*.visual.force.mil/*",
"https://*.vf.force.mil/*",
"https://*.lightning.force.mil/*",
"https://*.cloudforce.mil/*",
"https://*.visualforce.mil/*",
"https://*.crmforce.mil/*"
],
"all_frames": true,
"css": ["button.css", "inspect-inline.css"],
Expand Down
16 changes: 14 additions & 2 deletions addon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
"https://*.salesforce.com/*",
"https://*.force.com/*",
"https://*.cloudforce.com/*",
"https://*.visualforce.com/*"
"https://*.visualforce.com/*",
"https://*.salesforce.mil/*",
"https://*.force.mil/*",
"https://*.cloudforce.mil/*",
"https://*.visualforce.mil/*",
"https://*.crmforce.mil/*"
],
"content_scripts": [
{
Expand All @@ -21,7 +26,14 @@
"https://*.vf.force.com/*",
"https://*.lightning.force.com/*",
"https://*.cloudforce.com/*",
"https://*.visualforce.com/*"
"https://*.visualforce.com/*",
"https://*.salesforce.mil/*",
"https://*.visual.force.mil/*",
"https://*.vf.force.mil/*",
"https://*.lightning.force.mil/*",
"https://*.cloudforce.mil/*",
"https://*.visualforce.mil/*",
"https://*.crmforce.mil/*"
],
"all_frames": true,
"css": ["button.css", "inspect-inline.css"],
Expand Down
4 changes: 2 additions & 2 deletions addon/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ function getRecordId(href) {
// Find record ID from URL
let searchParams = new URLSearchParams(url.search.substring(1));
// Salesforce Classic and Console
if (url.hostname.endsWith(".salesforce.com")) {
if (url.hostname.endsWith(".salesforce.com") || url.hostname.endsWith(".salesforce.mil")) {
let match = url.pathname.match(/\/([a-zA-Z0-9]{3}|[a-zA-Z0-9]{15}|[a-zA-Z0-9]{18})(?:\/|$)/);
if (match) {
let res = match[1];
Expand All @@ -1582,7 +1582,7 @@ function getRecordId(href) {
}

// Lightning Experience and Salesforce1
if (url.hostname.endsWith(".lightning.force.com")) {
if (url.hostname.endsWith(".lightning.force.com") || url.hostname.endsWith(".lightning.force.mil") || url.hostname.endsWith(".lightning.crmforce.mil")) {
let match;

if (url.pathname == "/one/one.app") {
Expand Down

0 comments on commit 172cee2

Please sign in to comment.