Hi Kanchan,
This is a common issue when deploying Copilot Studio agents on SharePoint Online. The problem stems from how SharePoint handles iframe embedding and URL context isolation.
Root Cause
SharePoint Online isolates embedded content (like Copilot Studio agents) in iframes, which prevents direct access to the parent page's query string parameters. The agent runs in a separate context and cannot access the SharePoint page's URL directly.
Solutions
1. Use SharePoint Web Parts with Custom Properties
// In a SharePoint Framework (SPFx) web part
const urlParams = new URLSearchParams(window.location.search);
const paramValue = urlParams.get('yourParameter');
// Pass to Copilot agent via custom properties or postMessage
2. Implement PostMessage Communication
// On SharePoint page
window.addEventListener('load', function() {
const iframe = document.querySelector('#copilot-iframe');
const urlParams = new URLSearchParams(window.location.search);
iframe.contentWindow.postMessage({
type: 'sharepoint-params',
data: Object.fromEntries(urlParams)
}, '*');
});
3. Use SharePoint Context API
Configure your agent to receive context through SharePoint's web part properties:
{
"contextParameters": {
"siteUrl": "{{Site.Url}}",
"listId": "{{List.Id}}",
"customParam": "{{QueryString.yourParam}}"
}
}
4. Alternative: Custom Connector Approach
Create a Power Automate flow that:
- Captures SharePoint context
- Passes parameters to your Copilot agent
- Returns responses back to SharePoint
Recommended Implementation
Step 1: Modify your Copilot Studio agent to accept parameters via a custom action instead of global variables.
Step 2: Create a SharePoint Framework web part that:
- Reads the query string from the parent page
- Passes parameters to the embedded agent
- Handles the communication bridge
Step 3: Deploy the custom web part to your SharePoint app catalog.
Quick Workaround
If you need an immediate solution:
- Modify the SharePoint page to include a JavaScript snippet that extracts query parameters
- Use SharePoint's built-in script editor web part to inject the parameter into the agent's initialization
- Update your agent to receive the parameter through a different method (custom action or topic trigger)
SharePoint-Specific Considerations
- Security: SharePoint's Content Security Policy may block certain scripts
- Permissions: Ensure proper app permissions for cross-domain communication
- Updates: SharePoint updates may affect iframe behavior
- Mobile: Consider mobile SharePoint app limitations
The most robust solution is implementing a custom SPFx web part that properly handles the parameter passing between SharePoint and your Copilot agent.
This is the Feedback document link
Thanks,
Karan Shewale.
*************************************************************************
If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.