Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/extension/sendrequest/index.md
6552 views
---
title: extension.sendRequest() slug: Mozilla/Add-ons/WebExtensions/API/extension/sendRequest page-type: webextension-api-function tags: - API - Add-ons - Deprecated - Extension - Extensions - Method - Non-standard - Reference - WebExtensions - sendRequest browser-compat: webextensions.api.extension.sendRequest
---

{{AddonSidebar}}{{Deprecated_Header}}

Warning: This method has been deprecated. Use {{WebExtAPIRef("runtime.sendMessage")}} instead.

Sends a single request to other listeners within the extension. Similar to {{WebExtAPIRef('runtime.connect')}}, but only sends a single request with an optional response. The {{WebExtAPIRef('extension.onRequest')}} event is fired in each page of the extension.

Syntax

chrome.extension.sendRequest( extensionId, // optional string request, // any (response) => {/* … */} // optional function )

This API is also available as browser.extension.sendRequest() in a version that returns a promise.

Parameters

  • extensionId {{optional_inline}}

    • : string. The extension ID of the extension you want to connect to. If omitted, default is your own extension.

  • request

    • : any.

  • responseCallback {{optional_inline}}

    • : function. The function is passed the following arguments:

      • response

        • : any. The JSON response object sent by the handler of the request. If an error occurs while connecting to the extension, the callback will be called with no arguments and {{WebExtAPIRef('runtime.lastError')}} will be set to the error message.

Browser compatibility

{{Compat}}

{{WebExtExamples}}

Note: This API is based on Chromium's chrome.extension API. This documentation is derived from extension.json in the Chromium code.