Our goal is to standarize the window.cs2inventory
api for all extensions to use. Any extension can provide spec-compliant implementation of window.cs2inventory
for any site to use. This way users can benefit from extension on all websites, similarly to how many web3 wallets share the same API.
Discuss: https://discord.gg/kXJGt9vPhy
function loadInventory(appId: number, contextId: number | string): Promise<SteamInventory>
Check if cs2inventory is present in user browser. Fetch inventory using the extension and send to your API for processing
<script>
// Client-side code, this is executed in browser
if ('cs2inventory' in window) {
const inventory = await window.cs2inventory.loadInventory(730, 2)
reportUserInventory(inventory)
}
async function reportUserInventory(inventory) {
// All request to this endpoint should be treated as UNSAFE
return fetch('/api/report-user-inventory', {
method: 'POST',
body: JSON.stringify(inventory)
})
}
</script>
Build the extension in development or production mode:
npm install
npm run dev
Then load the extension into your browser:
- Visit
chrome://extensions
- Enable developer mode (upper right corner)
- Click "Load unpacked"
- Select
build/chrome-mv3-dev
directory from this repository
- Visit
chrome://extensions
- Click "service worker" under the extension card