Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
Chrome extension ExecuteScript not firing XRM JavaScript

Dynamics CRM has its own XRM JS APIs, Which I'm trying to execute in a chrome extension that I'm working on. I'm using the below code.

chrome.tabs.query({ currentWindow: true, active: true }, function(tabs) {
  chrome.scripting.executeScript({
    target: { tabId: tabs[0].id },
    func: () => {
      Xrm.Utility.alertDialog("Hello world", () => { });
    }
  });
});
Xrm.Utility.alertDialog("Hello world", () => { });

This code just shows a message box on the Dynamics CRM screen using this Dynamics API method.

If I run this code in the chrome console, it shows the message properly. If I just put alert("Hello world")", that code also runs which confirms that executeScript is working fine, but somehow Xrm isn't available.

Manifest.json enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After overflowing the stack a few times, I learned that the script injection needs to happen by explicitly creating a script tag and injecting it on the page body. similar to the code below.

function runOnXrmPage() {

    // create a script tag
    var s = document.createElement('script');
    s.src = chrome.runtime.getURL('webscript.js');
    s.onload = function () {
        this.remove();
    };
    (document.head || document.documentElement).appendChild(s);

}

chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
            chrome.scripting.executeScript({
                target: { tabId: tabs[0].id },
                func: () => {
                    runOnXrmPage();
                }
            });
});


All the Xrm code was placed in webscript.js file and manifest was updated as pasted below.

  "web_accessible_resources": [
    {
      "resources": [ "webscript.js" ],
      "matches": [ "https://*.crm.dynamics.com/*" ]
    }
  ]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!