# 我如何将数据传递给artifact？

**URL:** <https://meta.discourse.org/t/how-do-i-pass-data-to-an-artifact/350791>\
**Category:** Feature\
**Tags:** completed, ai, ai-artifacts\
**Created:** [2025年二月5日 19:15 UTC](https://meta.discourse.org/t/how-do-i-pass-data-to-an-artifact/350791 "2025-02-05T19:15:07Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2025年五月18日 01:54 UTC](https://meta.discourse.org/t/how-do-i-pass-data-to-an-artifact/350791/10 "2025-05-18T01:54:16Z")

</div>

> <https://github.com/discourse/discourse-ai/pull/1346/>
>
> Also allow artifact access to current username
> 
> Usage inside artifact is:
> 
> 1…. await window.discourseArtifactReady;
> 2. access data via window.discourseArtifactData;
> 
> \`\`\`
> \<div class="ai-artifact" data-ai-artifact-id="482" data-hello="world"\>\</div\>
> \`\`\`
> 
> 
> !\[image\](https://github.com/user-attachments/assets/9cd2fa52-6248-4eaf-b6c2-9783d3fc83f0)

这将解决此问题。由于沙盒化，这里确实没有简单的选择，只能使用 post message，因此 API 需要 await……不过它确实有效，这很好。

---

_[View the full topic](https://meta.discourse.org/t/how-do-i-pass-data-to-an-artifact/350791)._
