---
schema_version: "1"
id: 657c84be3579b519d33c5c19eeeb061a8a812240ec19585764f95c4be00d5baa
title: Getting Context in Your Canvas App
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/canvas-framework/guides/platform-connect/using/canvas-app-getting-context-code-example.md
canonical_url: https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-app-getting-context-code-example.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 92c54b750d0b0f3454c787e720fc2151ba90b8659dcc5bebf60406b184dc5782
products:
  - Canvas Developer Guide
  - Platform Developer Content
---

# Getting Context in Your Canvas App

When you authenticate your canvas app using signed request, you get the [CanvasRequest](https://developer.salesforce.com/docs/platform/canvas-framework/reference/canvas-request-object.md) object (which contains the Context object) as part of the POST to the canvas app URL. If you’re authenticating using OAuth, or you want to make a call to get context information, you can do so by making a JavaScript call.

**note:** Getting context data from the Canvas SDK is the most reliable way to identify users. Browsers may not send your canvas app cookies or other identifying data. See [Alternatives to Cookies for User Tracking](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-app-iframe-considerations.md).

The following code sample is an example of a JavaScript call to get context. This code creates a link with the text “Get Context” which then calls the `Sfdc.canvas.client.ctx` function.

<!-- otherprops: set_clipboard -->
```java
<script>
    function callback(msg) {
       if (msg.status !== 200) {
          alert("Error: " + msg.status);
          return;
       }
       alert("Payload: ", msg.payload);
    }
                
    var ctxlink = Sfdc.canvas.byId("ctxlink");
    var client = Sfdc.canvas.oauth.client();
    ctxlink.onclick=function() {
       Sfdc.canvas.client.ctx(callback, client)};
    }
</script>

<a id="ctxlink" href="#">Get Context</a>

```

**See Also**  


-   [Canvas SDK](https://developer.salesforce.com/docs/platform/canvas-framework/guide/canvas-framework-using-sdk.md)
-   [Context](https://developer.salesforce.com/docs/platform/canvas-framework/reference/context-object.md)
-   [Filtering CanvasRequest Context Data](https://developer.salesforce.com/docs/platform/canvas-framework/guide/lifecycle/canvas-filtering-context-data.md)

