Chromium 中chrome.webRequest扩展接口定义c++
一、chrome.webRequest
注意:从 Manifest V3 开始,"webRequestBlocking"
权限不再适用于大多数扩展程序。以"declarativeNetRequest"
为例,它允许使用declarativeNetRequest API。除了"webRequestBlocking"
之外,webRequest API 保持不变,仍可正常使用。通过政策安装的扩展程序可以继续使用"webRequestBlocking"
。
使用chrome.webRequest
API 可观察和分析流量,以及拦截、阻止或修改传输中的请求。
权限
webRequest
您必须在扩展程序清单中声明"webRequest"
权限,才能使用 Web 请求 API 以及必要的主机权限。要拦截子资源请求, 扩展程序必须同时有权访问请求的网址及其发起者。例如:
{"name": "My extension",..."permissions": ["webRequest"],"host_permissions": ["*://*.google.com/*"],...
}
webRequestBlocking
必须填写此字段,才能注册屏蔽事件处理脚本。从 Manifest V3 开始, 适用于通过政策安装的扩展程序
webRequestAuthProvider
使用onAuthRequired方法的必需条件。请参阅处理身份验证。
请求的生命周期
Web 请求 API 定义了一组遵循 Web 请求生命周期的事件。您可以使用 来观察和分析流量。某些同步事件允许您拦截、 屏蔽或修改请求
成功请求的事件生命周期如下所示,其后是事件定义:
更多参考chrome.webRequest ?|? API ?|? Chrome for Developers
二、chrome.webRequest c++接口定义:
1、web_request.json接口描述文件:
extensionscommonapiweb_request.json
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.[{"namespace": "webRequest","description": "Use the <code>chrome.webRequest</code> API to observe and analyze traffic and to intercept, block, or modify requests in-flight.","properties": {"MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES": {"value": 20,"description": "The maximum number of times that <code>handlerBehaviorChanged</code> can be called per 10 minute sustained interval. <code>handlerBehaviorChanged</code> is an expensive function call that shouldn't be called often."}},"types": [{"id": "ResourceType","type": "string","enum": [{"name": "main_frame", "description": "Specifies the resource as the main frame."},{"name": "sub_frame", "description": "Specifies the resource as a sub frame."},{"name": "stylesheet", "description": "Specifies the resource as a stylesheet."},{"name": "script", "description": "Specifies the resource as a script."},{"name": "image", "description": "Specifies the resource as an image."},{"name": "font", "description": "Specifies the resource as a font."},{"name": "object", "description": "Specifies the resource as an object."},{"name": "xmlhttprequest","description": "Specifies the resource as an XMLHttpRequest."},{"name": "ping","description": "Specifies the resource as a ping."},{"name": "csp_report","description": "Specifies the resource as a Content Security Policy (CSP) report."},{"name": "media", "description": "Specifies the resource as a media object."},{"name": "websocket", "description": "Specifies the resource as a WebSocket."},{"name": "webbundle", "description": "Specifies the resource as a WebBundle."},{"name": "other", "description": "Specifies the resource as a type not included in the listed types."}]},{"id": "OnBeforeRequestOptions","type": "string","enum": [{"name": "blocking", "description": "Specifies the request is blocked until the callback function returns."},{"name": "requestBody", "description": "Specifies that the request body should be included in the event."},{"name": "extraHeaders", "description": "Specifies that headers can violate Cross-Origin Resource Sharing (CORS)."}]},{"id": "OnBeforeSendHeadersOptions","type": "string","enum": [{"name": "requestHeaders", "description": "Specifies that the request header should be included in the event."},{"name": "blocking", "description": "Specifies the request is blocked until the callback function returns."},{"name": "extraHeaders", "description": "Specifies that headers can violate Cross-Origin Resource Sharing (CORS)."}]},{"id": "OnSendHeadersOptions","type": "string","enum": [{"name": "requestHeaders", "description": "Specifies that the request header should be included in the event."},{"name": "extraHeaders", "description": "Specifies that headers can violate Cross-Origin Resource Sharing (CORS)."}]},{"id": "OnHeadersReceivedOptions","type": "string","enum": [{"name": "blocking", "description": "Specifies the request is blocked until the callback function returns."},{"name": "responseHeaders", "description": "Specifies that the response headers should be included in the event."},{"name": "extraHeaders", "description": "Specifies that headers can violate Cross-Origin Resource Sharing (CORS)."}]},{"id": "OnAuthRequiredOptions","type": "string","enum": [{"name": "responseHeaders", "description": "Specifies that the response headers should be included in the event."},{"name": "blocking", "description": "Specifies the request is blocked until the callback function returns."},{"name": "asyncBlocking", "description": "Specifies that the callback function is handled asynchronously."},{"name": "extraHeaders", "description": "Specifies that headers can violate Cross-Origin Resource Sharing (CORS)."}]},{"id": "OnResponseStartedOptions","type": "string","enum": [{"name": "responseHeaders", "description": "Specifies that the response headers should be included in the event."},{"name": "extraHeaders", "description": "Specifies that headers can violate Cross-Origin Resource Sharing (CORS)."}]},{"id": "OnBeforeRedirectOptions","type": "string","enum": [{"name": "responseHeaders", "description": "Specifies that the response headers should be included in the event."},{"name": "extraHeaders", "description": "Specifies that headers can violate Cross-Origin Resource Sharing (CORS)."}]},{"id": "OnCompletedOptions","type": "string","enum": [{"name": "responseHeaders", "description": "Specifies that the response headers should be included in the event."},{"name": "extraHeaders", "description": "Specifies that headers can violate Cross-Origin Resource Sharing (CORS)."}]},{"id": "OnErrorOccurredOptions","type": "string","enum": [{"name": "extraHeaders", "description": "Specifies that headers can violate Cross-Origin Resource Sharing (CORS)."}]},{"id": "RequestFilter","type": "object","description": "An object describing filters to apply to webRequest events.","properties": {"urls": {"type": "array","description": "A list of URLs or URL patterns. Requests that cannot match any of the URLs will be filtered out.","items": { "type": "string" }},"types": {"type": "array","optional": true,"description": "A list of request types. Requests that cannot match any of the types will be filtered out.","items": { "$ref": "ResourceType" }},"tabId": { "type": "integer", "optional": true },"windowId": { "type": "integer", "optional": true }}},{"id": "HttpHeaders","nocompile": true,"type": "array","description": "An array of HTTP headers. Each header is represented as a dictionary containing the keys <code>name</code> and either <code>value</code> or <code>binaryValue</code>.","items": {"type": "object","properties": {"name": {"type": "string", "description": "Name of the HTTP header."},"value": {"type": "string", "optional": true, "description": "Value of the HTTP header if it can be represented by UTF-8."},"binaryValue": {"type": "array","optional": true,"description": "Value of the HTTP header if it cannot be represented by UTF-8, stored as individual byte values (0..255).","items": {"type": "integer"}}}}},{"id": "BlockingResponse","nocompile": true,"type": "object","description": "Returns value for event handlers that have the 'blocking' extraInfoSpec applied. Allows the event handler to modify network requests.","properties": {"cancel": {"type": "boolean","optional": true,"description": "If true, the request is cancelled. This prevents the request from being sent. This can be used as a response to the onBeforeRequest, onBeforeSendHeaders, onHeadersReceived and onAuthRequired events."},"redirectUrl": {"type": "string","optional": true,"description": "Only used as a response to the onBeforeRequest and onHeadersReceived events. If set, the original request is prevented from being sent/completed and is instead redirected to the given URL. Redirections to non-HTTP schemes such as <code>data:</code> are allowed. Redirects initiated by a redirect action use the original request method for the redirect, with one exception: If the redirect is initiated at the onHeadersReceived stage, then the redirect will be issued using the GET method. Redirects from URLs with <code>ws://</code> and <code>wss://</code> schemes are <b>ignored</b>."},"requestHeaders": {"$ref": "HttpHeaders","optional": true,"description": "Only used as a response to the onBeforeSendHeaders event. If set, the request is made with these request headers instead."},"responseHeaders": {"$ref": "HttpHeaders","optional": true,"description": "Only used as a response to the onHeadersReceived event. If set, the server is assumed to have responded with these response headers instead. Only return <code>responseHeaders</code> if you really want to modify the headers in order to limit the number of conflicts (only one extension may modify <code>responseHeaders</code> for each request)."},"authCredentials": {"type": "object","description": "Only used as a response to the onAuthRequired event. If set, the request is made using the supplied credentials.","optional": true,"properties": {"username": {"type": "string"},"password": {"type": "string"}}}}},{"id": "UploadData","type": "object","properties": {"bytes": {"type": "any","optional": true,"description": "An ArrayBuffer with a copy of the data."},"file": {"type": "string","optional": true,"description": "A string with the file's path and name."}},"description": "Contains data uploaded in a URL request."},{"id": "FormDataItem","choices": [{ "type": "binary" },{ "type": "string" }],"description": "Contains data passed within form data. For urlencoded form it is stored as string if data is utf-8 string and as ArrayBuffer otherwise. For form-data it is ArrayBuffer. If form-data represents uploading file, it is string with filename, if the filename is provided."},{"id": "IgnoredActionType","decription": "Denotes the extension proposed action which was ignored.","type": "string","enum": ["redirect", "request_headers", "response_headers", "auth_credentials"]}],"functions": [{"name": "handlerBehaviorChanged","type": "function","description": "Needs to be called when the behavior of the webRequest handlers has changed to prevent incorrect handling due to caching. This function call is expensive. Don't call it often.","parameters": [],"returns_async": {"name": "callback", "optional": true, "parameters": []}}],"events": [{"name": "onBeforeRequest","type": "function","description": "Fired when a request is about to occur.","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"url": {"type": "string"},"method": {"type": "string", "description": "Standard HTTP method."},"frameId": {"type": "integer", "description": "The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},"documentId": {"type": "string", "optional": true, "description": "The UUID of the document making the request."},"parentDocumentId": {"type": "string", "optional": true, "description": "The UUID of the parent document owning this frame. This is not set if there is no parent."},"documentLifecycle": {"$ref": "extensionTypes.DocumentLifecycle", "optional": true, "description": "The lifecycle the document is in."},"frameType": {"$ref": "extensionTypes.FrameType", "optional": true, "description": "The type of frame the request occurred in."},"requestBody": {"type": "object","optional": true,"description": "Contains the HTTP request body data. Only provided if extraInfoSpec contains 'requestBody'.","properties": {"error": {"type": "string", "optional": true, "description": "Errors when obtaining request body data."},"formData": {"type": "object","optional": true,"description": "If the request method is POST and the body is a sequence of key-value pairs encoded in UTF8, encoded as either multipart/form-data, or application/x-www-form-urlencoded, this dictionary is present and for each key contains the list of all values for that key. If the data is of another media type, or if it is malformed, the dictionary is not present. An example value of this dictionary is {'key': ['value1', 'value2']}.","properties": {},"additionalProperties": {"type": "array","items": { "$ref": "FormDataItem" }}},"raw" : {"type": "array","optional": true,"items": {"$ref": "UploadData"},"description": "If the request method is PUT or POST, and the body is not already parsed in formData, then the unparsed request body elements are contained in this array."}}},"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},"type": {"$ref": "ResourceType", "description": "How the requested resource will be used."},"initiator": {"type": "string", "optional": true, "description": "The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used."},"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."}}}],"extraParameters": [{"$ref": "RequestFilter","name": "filter","description": "A set of filters that restricts the events that will be sent to this listener."},{"type": "array","optional": true,"name": "extraInfoSpec","description": "Array of extra information that should be passed to the listener function.","items": {"$ref": "OnBeforeRequestOptions"}}],"returns": {"$ref": "BlockingResponse","description": "If "blocking" is specified in the "extraInfoSpec" parameter, the event listener should return an object of this type.","optional": true}},{"name": "onBeforeSendHeaders","nocompile": true,"type": "function","description": "Fired before sending an HTTP request, once the request headers are available. This may occur after a TCP connection is made to the server, but before any HTTP data is sent. ","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"url": {"type": "string"},"method": {"type": "string", "description": "Standard HTTP method."},"frameId": {"type": "integer", "description": "The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},"documentId": {"type": "string", "description": "The UUID of the document making the request."},"parentDocumentId": {"type": "string", "optional": true, "description": "The UUID of the parent document owning this frame. This is not set if there is no parent."},"documentLifecycle": {"$ref": "extensionTypes.DocumentLifecycle", "description": "The lifecycle the document is in."},"frameType": {"$ref": "extensionTypes.FrameType", "description": "The type of frame the request occurred in."},"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},"initiator": {"type": "string", "optional": true, "description": "The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used."},"type": {"$ref": "ResourceType", "description": "How the requested resource will be used."},"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},"requestHeaders": {"$ref": "HttpHeaders", "optional": true, "description": "The HTTP request headers that are going to be sent out with this request."}}}],"extraParameters": [{"$ref": "RequestFilter","name": "filter","description": "A set of filters that restricts the events that will be sent to this listener."},{"type": "array","optional": true,"name": "extraInfoSpec","description": "Array of extra information that should be passed to the listener function.","items": {"$ref": "OnBeforeSendHeadersOptions"}}],"returns": {"$ref": "BlockingResponse","description": "If "blocking" is specified in the "extraInfoSpec" parameter, the event listener should return an object of this type.","optional": true}},{"name": "onSendHeaders","nocompile": true,"type": "function","description": "Fired just before a request is going to be sent to the server (modifications of previous onBeforeSendHeaders callbacks are visible by the time onSendHeaders is fired).","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"url": {"type": "string"},"method": {"type": "string", "description": "Standard HTTP method."},"frameId": {"type": "integer", "description": "The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},"documentId": {"type": "string", "description": "The UUID of the document making the request."},"parentDocumentId": {"type": "string", "optional": true, "description": "The UUID of the parent document owning this frame. This is not set if there is no parent."},"documentLifecycle": {"$ref": "extensionTypes.DocumentLifecycle", "description": "The lifecycle the document is in."},"frameType": {"$ref": "extensionTypes.FrameType", "description": "The type of frame the request occurred in."},"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},"type": {"$ref": "ResourceType", "description": "How the requested resource will be used."},"initiator": {"type": "string", "optional": true, "description": "The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used."},"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},"requestHeaders": {"$ref": "HttpHeaders", "optional": true, "description": "The HTTP request headers that have been sent out with this request."}}}],"extraParameters": [{"$ref": "RequestFilter","name": "filter","description": "A set of filters that restricts the events that will be sent to this listener."},{"type": "array","optional": true,"name": "extraInfoSpec","description": "Array of extra information that should be passed to the listener function.","items": {"$ref": "OnSendHeadersOptions"}}]},{"name": "onHeadersReceived","nocompile": true,"type": "function","description": "Fired when HTTP response headers of a request have been received.","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"url": {"type": "string"},"method": {"type": "string", "description": "Standard HTTP method."},"frameId": {"type": "integer", "description": "The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},"documentId": {"type": "string", "description": "The UUID of the document making the request."},"parentDocumentId": {"type": "string", "optional": true, "description": "The UUID of the parent document owning this frame. This is not set if there is no parent."},"documentLifecycle": {"$ref": "extensionTypes.DocumentLifecycle", "description": "The lifecycle the document is in."},"frameType": {"$ref": "extensionTypes.FrameType", "description": "The type of frame the request occurred in."},"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},"type": {"$ref": "ResourceType", "description": "How the requested resource will be used."},"initiator": {"type": "string", "optional": true, "description": "The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used."},"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},"statusLine": {"type": "string", "description": "HTTP status line of the response or the 'HTTP/0.9 200 OK' string for HTTP/0.9 responses (i.e., responses that lack a status line)."},"responseHeaders": {"$ref": "HttpHeaders", "optional": true, "description": "The HTTP response headers that have been received with this response."},"statusCode": {"type": "integer", "description": "Standard HTTP status code returned by the server."}}}],"extraParameters": [{"$ref": "RequestFilter","name": "filter","description": "A set of filters that restricts the events that will be sent to this listener."},{"type": "array","optional": true,"name": "extraInfoSpec","description": "Array of extra information that should be passed to the listener function.","items": {"$ref": "OnHeadersReceivedOptions"}}],"returns": {"$ref": "BlockingResponse","description": "If "blocking" is specified in the "extraInfoSpec" parameter, the event listener should return an object of this type.","optional": true}},{"name": "onAuthRequired","nocompile": true,"type": "function","description": "Fired when an authentication failure is received. The listener has three options: it can provide authentication credentials, it can cancel the request and display the error page, or it can take no action on the challenge. If bad user credentials are provided, this may be called multiple times for the same request. Note, only one of <code>'blocking'</code> or <code>'asyncBlocking'</code> modes must be specified in the <code>extraInfoSpec</code> parameter.","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"url": {"type": "string"},"method": {"type": "string", "description": "Standard HTTP method."},"frameId": {"type": "integer", "description": "The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},"documentId": {"type": "string", "description": "The UUID of the document making the request."},"parentDocumentId": {"type": "string", "optional": true, "description": "The UUID of the parent document owning this frame. This is not set if there is no parent."},"documentLifecycle": {"$ref": "extensionTypes.DocumentLifecycle", "description": "The lifecycle the document is in."},"frameType": {"$ref": "extensionTypes.FrameType", "description": "The type of frame the request occurred in."},"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},"type": {"$ref": "ResourceType", "description": "How the requested resource will be used."},"initiator": {"type": "string", "optional": true, "description": "The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used."},"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},"scheme": {"type": "string", "description": "The authentication scheme, e.g. Basic or Digest."},"realm": {"type": "string", "description": "The authentication realm provided by the server, if there is one.", "optional": true},"challenger": {"type": "object", "description": "The server requesting authentication.", "properties": {"host": {"type": "string"}, "port": {"type": "integer"}}},"isProxy": {"type": "boolean", "description": "True for Proxy-Authenticate, false for WWW-Authenticate."},"responseHeaders": {"$ref": "HttpHeaders", "optional": true, "description": "The HTTP response headers that were received along with this response."},"statusLine": {"type": "string", "description": "HTTP status line of the response or the 'HTTP/0.9 200 OK' string for HTTP/0.9 responses (i.e., responses that lack a status line) or an empty string if there are no headers."},"statusCode": {"type": "integer", "description": "Standard HTTP status code returned by the server."}}},{"type": "function","optional": true,"description" : "Only valid if <code>'asyncBlocking'</code> is specified as one of the <code>OnAuthRequiredOptions</code>.","name": "asyncCallback","parameters": [{"name": "response", "$ref": "BlockingResponse"}]}],"extraParameters": [{"$ref": "RequestFilter","name": "filter","description": "A set of filters that restricts the events that will be sent to this listener."},{"type": "array","optional": true,"name": "extraInfoSpec","description": "Array of extra information that should be passed to the listener function.","items": {"$ref": "OnAuthRequiredOptions"}}],"returns": {"$ref": "BlockingResponse","description": "If "blocking" is specified in the "extraInfoSpec" parameter, the event listener should return an object of this type.","optional": true}},{"name": "onResponseStarted","nocompile": true,"type": "function","description": "Fired when the first byte of the response body is received. For HTTP requests, this means that the status line and response headers are available.","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"url": {"type": "string"},"method": {"type": "string", "description": "Standard HTTP method."},"frameId": {"type": "integer", "description": "The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},"documentId": {"type": "string", "description": "The UUID of the document making the request."},"parentDocumentId": {"type": "string", "optional": true, "description": "The UUID of the parent document owning this frame. This is not set if there is no parent."},"documentLifecycle": {"$ref": "extensionTypes.DocumentLifecycle", "description": "The lifecycle the document is in."},"frameType": {"$ref": "extensionTypes.FrameType", "description": "The type of frame the request occurred in."},"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},"type": {"$ref": "ResourceType", "description": "How the requested resource will be used."},"initiator": {"type": "string", "optional": true, "description": "The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used."},"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},"ip": {"type": "string", "optional": true, "description": "The server IP address that the request was actually sent to. Note that it may be a literal IPv6 address."},"fromCache": {"type": "boolean", "description": "Indicates if this response was fetched from disk cache."},"statusCode": {"type": "integer", "description": "Standard HTTP status code returned by the server."},"responseHeaders": {"$ref": "HttpHeaders", "optional": true, "description": "The HTTP response headers that were received along with this response."},"statusLine": {"type": "string", "description": "HTTP status line of the response or the 'HTTP/0.9 200 OK' string for HTTP/0.9 responses (i.e., responses that lack a status line) or an empty string if there are no headers."}}}],"extraParameters": [{"$ref": "RequestFilter","name": "filter","description": "A set of filters that restricts the events that will be sent to this listener."},{"type": "array","optional": true,"name": "extraInfoSpec","description": "Array of extra information that should be passed to the listener function.","items": {"$ref": "OnResponseStartedOptions"}}]},{"name": "onBeforeRedirect","type": "function","nocompile": true,"description": "Fired when a server-initiated redirect is about to occur.","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"url": {"type": "string"},"method": {"type": "string", "description": "Standard HTTP method."},"frameId": {"type": "integer", "description": "The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},"documentId": {"type": "string", "description": "The UUID of the document making the request."},"parentDocumentId": {"type": "string", "optional": true, "description": "The UUID of the parent document owning this frame. This is not set if there is no parent."},"documentLifecycle": {"$ref": "extensionTypes.DocumentLifecycle", "description": "The lifecycle the document is in."},"frameType": {"$ref": "extensionTypes.FrameType", "description": "The type of frame the request occurred in."},"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},"type": {"$ref": "ResourceType", "description": "How the requested resource will be used."},"initiator": {"type": "string", "optional": true, "description": "The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used."},"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},"ip": {"type": "string", "optional": true, "description": "The server IP address that the request was actually sent to. Note that it may be a literal IPv6 address."},"fromCache": {"type": "boolean", "description": "Indicates if this response was fetched from disk cache."},"statusCode": {"type": "integer", "description": "Standard HTTP status code returned by the server."},"redirectUrl": {"type": "string", "description": "The new URL."},"responseHeaders": {"$ref": "HttpHeaders", "optional": true, "description": "The HTTP response headers that were received along with this redirect."},"statusLine": {"type": "string", "description": "HTTP status line of the response or the 'HTTP/0.9 200 OK' string for HTTP/0.9 responses (i.e., responses that lack a status line) or an empty string if there are no headers."}}}],"extraParameters": [{"$ref": "RequestFilter","name": "filter","description": "A set of filters that restricts the events that will be sent to this listener."},{"type": "array","optional": true,"name": "extraInfoSpec","description": "Array of extra information that should be passed to the listener function.","items": {"$ref": "OnBeforeRedirectOptions"}}]},{"name": "onCompleted","type": "function","nocompile": true,"description": "Fired when a request is completed.","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"url": {"type": "string"},"method": {"type": "string", "description": "Standard HTTP method."},"frameId": {"type": "integer", "description": "The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},"documentId": {"type": "string", "description": "The UUID of the document making the request."},"parentDocumentId": {"type": "string", "optional": true, "description": "The UUID of the parent document owning this frame. This is not set if there is no parent."},"documentLifecycle": {"$ref": "extensionTypes.DocumentLifecycle", "description": "The lifecycle the document is in."},"frameType": {"$ref": "extensionTypes.FrameType", "description": "The type of frame the request occurred in."},"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},"type": {"$ref": "ResourceType", "description": "How the requested resource will be used."},"initiator": {"type": "string", "optional": true, "description": "The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used."},"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},"ip": {"type": "string", "optional": true, "description": "The server IP address that the request was actually sent to. Note that it may be a literal IPv6 address."},"fromCache": {"type": "boolean", "description": "Indicates if this response was fetched from disk cache."},"statusCode": {"type": "integer", "description": "Standard HTTP status code returned by the server."},"responseHeaders": {"$ref": "HttpHeaders", "optional": true, "description": "The HTTP response headers that were received along with this response."},"statusLine": {"type": "string", "description": "HTTP status line of the response or the 'HTTP/0.9 200 OK' string for HTTP/0.9 responses (i.e., responses that lack a status line) or an empty string if there are no headers."}}}],"extraParameters": [{"$ref": "RequestFilter","name": "filter","description": "A set of filters that restricts the events that will be sent to this listener."},{"type": "array","optional": true,"name": "extraInfoSpec","description": "Array of extra information that should be passed to the listener function.","items": {"$ref": "OnCompletedOptions"}}]},{"name": "onErrorOccurred","type": "function","description": "Fired when an error occurs.","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"url": {"type": "string"},"method": {"type": "string", "description": "Standard HTTP method."},"frameId": {"type": "integer", "description": "The value 0 indicates that the request happens in the main frame; a positive value indicates the ID of a subframe in which the request happens. If the document of a (sub-)frame is loaded (<code>type</code> is <code>main_frame</code> or <code>sub_frame</code>), <code>frameId</code> indicates the ID of this frame, not the ID of the outer frame. Frame IDs are unique within a tab."},"parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."},"documentId": {"type": "string", "description": "The UUID of the document making the request. This value is not present if the request is a navigation of a frame."},"parentDocumentId": {"type": "string", "optional": true, "description": "The UUID of the parent document owning this frame. This is not set if there is no parent."},"documentLifecycle": {"$ref": "extensionTypes.DocumentLifecycle", "description": "The lifecycle the document is in."},"frameType": {"$ref": "extensionTypes.FrameType", "description": "The type of frame the request occurred in."},"tabId": {"type": "integer", "description": "The ID of the tab in which the request takes place. Set to -1 if the request isn't related to a tab."},"type": {"$ref": "ResourceType", "description": "How the requested resource will be used."},"initiator": {"type": "string", "optional": true, "description": "The origin where the request was initiated. This does not change through redirects. If this is an opaque origin, the string 'null' will be used."},"timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."},"ip": {"type": "string", "optional": true, "description": "The server IP address that the request was actually sent to. Note that it may be a literal IPv6 address."},"fromCache": {"type": "boolean", "description": "Indicates if this response was fetched from disk cache."},"error": {"type": "string", "description": "The error description. This string is <em>not</em> guaranteed to remain backwards compatible between releases. You must not parse and act based upon its content."}}}],"extraParameters": [{"$ref": "RequestFilter","name": "filter","description": "A set of filters that restricts the events that will be sent to this listener."},{"type": "array","optional": true,"name": "extraInfoSpec","description": "Array of extra information that should be passed to the listener function.","items": {"$ref": "OnErrorOccurredOptions"}}]},{"name": "onActionIgnored","type": "function","description": "Fired when an extension's proposed modification to a network request is ignored. This happens in case of conflicts with other extensions.","parameters": [{"type": "object","name": "details","properties": {"requestId": {"type": "string", "description": "The ID of the request. Request IDs are unique within a browser session. As a result, they could be used to relate different events of the same request."},"action": {"$ref": "IgnoredActionType", "description": "The proposed action which was ignored."}}}]}]}
]
2、web_request.json生成的c++文件:
outDebuggenextensionscommonapiweb_request.h
outDebuggenextensionscommonapiweb_request.cc
3、web_request api接口定义c++:
extensionsrowserapiweb_requestweb_request_api.h
extensionsrowserapiweb_requestweb_request_api.cc
namespace extensions {// Support class for the WebRequest API. Lives on the UI thread. Most of the
// work is done by ExtensionWebRequestEventRouter below. This class observes
// extensions::EventRouter to deal with event listeners. There is one instance
// per BrowserContext which is shared with incognito.
class WebRequestAPI : public BrowserContextKeyedAPI,public EventRouter::Observer,public ExtensionRegistryObserver {public:// A callback used to asynchronously respond to an intercepted authentication// request. If |should_cancel| is true the request will be cancelled.// Otherwise any supplied |credentials| will be used. If no credentials are// supplied, default browser behavior will follow (e.g. UI prompt for login).using AuthRequestCallback = base::OnceCallback<void(const std::optional<net::AuthCredentials>& credentials,bool should_cancel)>;// An interface which is held by ProxySet defined below.class Proxy {public:virtual ~Proxy() = default;// Asks the Proxy to handle an auth request on behalf of one of its known// in-progress network requests. If the request will *not* be handled by// the proxy, |callback| should be invoked with |std::nullopt|.virtual void HandleAuthRequest(const net::AuthChallengeInfo& auth_info,scoped_refptr<net::HttpResponseHeaders> response_headers,int32_t request_id,AuthRequestCallback callback);};// A ProxySet is a set of proxies used by WebRequestAPI: It holds Proxy// instances, and removes all proxies when it is destroyed.class ProxySet {public:ProxySet();ProxySet(const ProxySet&) = delete;ProxySet& operator=(const ProxySet&) = delete;~ProxySet();// Add a Proxy.void AddProxy(std::unique_ptr<Proxy> proxy);// Remove a Proxy. The removed proxy is deleted upon this call.void RemoveProxy(Proxy* proxy);// Associates |proxy| with |id|. |proxy| must already be registered within// this ProxySet.//// Each Proxy may be responsible for multiple requests, but any given// request identified by |id| must be associated with only a single proxy.void AssociateProxyWithRequestId(Proxy* proxy,const content::GlobalRequestID& id);// Disassociates |proxy| with |id|. |proxy| must already be registered// within this ProxySet.void DisassociateProxyWithRequestId(Proxy* proxy,const content::GlobalRequestID& id);Proxy* GetProxyFromRequestId(const content::GlobalRequestID& id);void MaybeProxyAuthRequest(const net::AuthChallengeInfo& auth_info,scoped_refptr<net::HttpResponseHeaders> response_headers,const content::GlobalRequestID& request_id,AuthRequestCallback callback);private:// Although these members are initialized on the UI thread, we expect at// least one memory barrier before actually calling Generate in the IO// thread, so we don't protect them with a lock.std::set<std::unique_ptr<Proxy>, base::UniquePtrComparator> proxies_;// Bi-directional mapping between request ID and Proxy for faster lookup.std::map<content::GlobalRequestID, Proxy*> request_id_to_proxy_map_;std::map<Proxy*, std::set<content::GlobalRequestID>>proxy_to_request_id_map_;};class RequestIDGenerator {public:RequestIDGenerator();RequestIDGenerator(const RequestIDGenerator&) = delete;RequestIDGenerator& operator=(const RequestIDGenerator&) = delete;~RequestIDGenerator();// Generates a WebRequest ID. If the same (routing_id,// network_service_request_id) pair is passed to this as was previously// passed to SaveID(), the |request_id| passed to SaveID() will be returned.int64_t Generate(int32_t routing_id, int32_t network_service_request_id);// This saves a WebRequest ID mapped to the (routing_id,// network_service_request_id) pair. Clients must call Generate() with the// same ID pair to retrieve the |request_id|, or else there may be a memory// leak.void SaveID(int32_t routing_id,int32_t network_service_request_id,uint64_t request_id);private:int64_t id_ = 0;std::map<std::pair<int32_t, int32_t>, uint64_t> saved_id_map_;};explicit WebRequestAPI(content::BrowserContext* context);WebRequestAPI(const WebRequestAPI&) = delete;WebRequestAPI& operator=(const WebRequestAPI&) = delete;~WebRequestAPI() override;// BrowserContextKeyedAPI support:static BrowserContextKeyedAPIFactory<WebRequestAPI>* GetFactoryInstance();void Shutdown() override;// EventRouter::Observer overrides:void OnListenerRemoved(const EventListenerInfo& details) override;// If any WebRequest event listeners are currently active for this// BrowserContext, |*factory_request| is swapped out for a new request which// proxies through an internal URLLoaderFactory. This supports lifetime// observation and control on behalf of the WebRequest API.// |frame| and |render_process_id| are the frame and render process id in// which the URLLoaderFactory will be used. |frame| can be nullptr for// factories proxied for service worker.//// |navigation_response_task_runner| is a task runner that may be non-null for// navigation requests and can be used to run navigation request blocking// tasks.//// Returns |true| if the URLLoaderFactory will be proxied; |false| otherwise.bool MaybeProxyURLLoaderFactory(content::BrowserContext* browser_context,content::RenderFrameHost* frame,int render_process_id,content::ContentBrowserClient::URLLoaderFactoryType type,std::optional<int64_t> navigation_id,ukm::SourceIdObj ukm_source_id,mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>*header_client,scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner,const url::Origin& request_initiator = url::Origin());// Any request which requires authentication to complete will be bounced// through this method.//// If this returns |true|, |callback| will eventually be invoked on the UI// thread.bool MaybeProxyAuthRequest(content::BrowserContext* browser_context,const net::AuthChallengeInfo& auth_info,scoped_refptr<net::HttpResponseHeaders> response_headers,const content::GlobalRequestID& request_id,bool is_main_frame,AuthRequestCallback callback,WebViewGuest* web_view_guest);// Starts proxying the connection with |factory|. This function can be called// only when MayHaveProxies() returns true.void ProxyWebSocket(content::RenderFrameHost* frame,content::ContentBrowserClient::WebSocketFactory factory,const GURL& url,const net::SiteForCookies& site_for_cookies,const std::optional<std::string>& user_agent,mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>handshake_client);// Starts proxying WebTransport handshake.void ProxyWebTransport(content::RenderProcessHost& render_process_host,int frame_routing_id,const GURL& url,const url::Origin& initiator_origin,mojo::PendingRemote<network::mojom::WebTransportHandshakeClient>handshake_client,content::ContentBrowserClient::WillCreateWebTransportCallback callback);void ForceProxyForTesting();// Indicates whether or not the WebRequestAPI may have one or more proxies// installed to support the API.bool MayHaveProxies() const;// Indicates whether or not WebRequestAPI may have one or more proxies// installed to support intercepting websocket connections for extension// telemetry.// TODO(psarouthakis): This is here for the current implementation, but// will be refactored to live somewhere else so that we don't have to// create a full proxy just for telemetry.bool MayHaveWebsocketProxiesForExtensionTelemetry() const;// Indicates whether the WebRequestAPI is available to a RenderFrameHost// that embeds a WebView instance.bool IsAvailableToWebViewEmbedderFrame(content::RenderFrameHost* render_frame_host) const;bool HasExtraHeadersListenerForTesting();private:friend class BrowserContextKeyedAPIFactory<WebRequestAPI>;// BrowserContextKeyedAPI support:static const char* service_name() { return "WebRequestAPI"; }static const bool kServiceRedirectedInIncognito = true;static const bool kServiceIsNULLWhileTesting = true;// Checks if |MayHaveProxies()| has changed from false to true, and resets// URLLoaderFactories if so.void UpdateMayHaveProxies();// ExtensionRegistryObserver implementation.void OnExtensionLoaded(content::BrowserContext* browser_context,const Extension* extension) override;void OnExtensionUnloaded(content::BrowserContext* browser_context,const Extension* extension,UnloadedExtensionReason reason) override;// This a proxy API for the tasks that are posted. It is either called// when the task is run and forwards to the corresponding member function// in ExtensionWebRequestEventRouter, or not, if the owning BrowserContext// goes away or the WeakPtr instance bound in the callback is invalidated.void UpdateActiveListener(content::BrowserContext* browser_context,WebRequestEventRouter::ListenerUpdateType update_type,const ExtensionId& extension_id,const std::string& sub_event_name,int worker_thread_id,int64_t service_worker_version_id);// This a proxy API for the tasks that are posted. It is either called// when the task is run and forwards to the corresponding member function// in ExtensionWebRequestEventRouter, or not, if the owning BrowserContext// goes away or the WeakPtr instance bound in the callback is invalidated.void RemoveLazyListener(content::BrowserContext* browser_context,const ExtensionId& extension_id,const std::string& sub_event_name);// A count of active extensions for this BrowserContext that use web request// permissions.int web_request_extension_count_ = 0;const raw_ptr<content::BrowserContext, DanglingUntriaged> browser_context_;RequestIDGenerator request_id_generator_;std::unique_ptr<ProxySet> proxies_;// Stores the last result of |MayHaveProxies()|, so it can be used in// |UpdateMayHaveProxies()|.bool may_have_proxies_;base::WeakPtrFactory<WebRequestAPI> weak_factory_{this};
};class WebRequestInternalFunction : public ExtensionFunction {public:WebRequestInternalFunction() = default;protected:~WebRequestInternalFunction() override = default;const std::string& extension_id_safe() const {return extension() ? extension_id() : base::EmptyString();}
};class WebRequestInternalAddEventListenerFunction: public WebRequestInternalFunction {public:DECLARE_EXTENSION_FUNCTION("webRequestInternal.addEventListener",WEBREQUESTINTERNAL_ADDEVENTLISTENER)protected:~WebRequestInternalAddEventListenerFunction() override = default;// ExtensionFunction:ResponseAction Run() override;
};class WebRequestInternalEventHandledFunction: public WebRequestInternalFunction {public:DECLARE_EXTENSION_FUNCTION("webRequestInternal.eventHandled",WEBREQUESTINTERNAL_EVENTHANDLED)protected:~WebRequestInternalEventHandledFunction() override = default;private:// Unblocks the network request. Use this function when handling incorrect// requests from the extension that cannot be detected by the schema// validator.void OnError(const std::string& event_name,const std::string& sub_event_name,uint64_t request_id,int render_process_id,int web_view_instance_id,std::unique_ptr<WebRequestEventRouter::EventResponse> response);// ExtensionFunction:ResponseAction Run() override;
};class WebRequestHandlerBehaviorChangedFunction: public WebRequestInternalFunction {public:DECLARE_EXTENSION_FUNCTION("webRequest.handlerBehaviorChanged",WEBREQUEST_HANDLERBEHAVIORCHANGED)protected:~WebRequestHandlerBehaviorChangedFunction() override = default;// ExtensionFunction:void GetQuotaLimitHeuristics(extensions::QuotaLimitHeuristics* heuristics) const override;// Handle quota exceeded gracefully: Only warn the user but still execute the// function.void OnQuotaExceeded(std::string error) override;ResponseAction Run() override;
};} // namespace extensions
总结:
WebRequest API 接口c++定义介绍完毕,需要调试修改逻辑的可以在以上文件处更改。
相关文章:
Chromium 中chrome.webRequest扩展接口定义c++
一、chrome.webRequest 注意:从 Manifest V3 开始,"webRequestBlocking"权限不再适用于大多数扩展程序。以"declarativeNetRequest"为例,它允许使用declarativeNetRequest API。除了"webRequestBlocking"之外…...
极乐 15.2.6 | 清爽版简约美观音乐软件,支持网易云歌单导入
极乐是一款使用起来非常轻松的音乐播放软件,它拥有清新简洁的画面,专注于音乐播放功能。最新版本全面升级了64位架构,带来了前所未有的性能提升和更稳定的体验。通过优化内存管理,降低了应用对系统资源的占用,确保设备…...
如何在 Ubuntu 22.04 上安装 Graylog 开源日志管理平台
简介 Graylog 的开源特性、丰富的功能、灵活性和可扩展性使其成为一个流行的日志管理平台。在本教程中,我将向你展示如何在 Ubuntu 22.04 上安装 Graylog,包括配置 Graylog 服务器软件包和访问 Graylog Web UI。 Graylog 是什么? Graylog …...
Wux weapp 组件库的 bug—— wux-picker选择器组件无法正确初始化到选定的value
options的value为Number,组件无法正常使用 解决方案,修改picker-view/utils.js中的getIndexFromValue函数,如下: export function getIndexFromValue(value, col [], fieldNames DEFAULT_FIELD_NAMES) {//return getRealIndex(…...
决策树(理论知识1)
目录 何为决策树决策树的组成决策树的构建 何为决策树 决策树(Decision Tree)是一种分类和回归方法,是基于各种情况发生的所需条件构成决策树,以实现期望最大化的一种图解法。由于这种决策 分支画成图形很像一棵树的枝干,故称决策树。它的运…...
【Spring】获取Bean对象需要哪些注解
阿华代码,不是逆风,就是我疯 你们的点赞收藏是我前进最大的动力!! 希望本文内容能够帮助到你!! 目录 一:Service(服务存储) 1:存储bean的代码 2࿱…...
java的Webclient对象怎解解析400状态码
在Java中使用WebClient处理400状态码,可以通过检查响应状态并根据状态码进行相应的错误处理。以下是几种处理400状态码的方法: 使用onStatus方法判断和处理错误: 你可以使用WebClient的retrieve()方法链中的onStatus方法来检查响应状态码。如…...
【计算机视觉基础CV-图像分类】03-深度学习图像分类实战:鲜花数据集加载与预处理详解
本文将深入介绍鲜花分类数据集的加载与处理方式,同时详细解释代码的每一步骤并给出更丰富的实践建议和拓展思路。以实用为导向,为读者提供从数据组织、预处理、加载到可视化展示的完整过程,并为后续模型训练打下基础。 前言 在计算机视觉的深…...
ubuntu 如何重装你的apt【apt-get报错: symbol lookup error/undefined symbol】
副标题:解决error:apt-get: symbol lookup error: /lib/x86_64-linux-gnu/libapt-private.so.0.0: undefined symbol: _ZNK13pkgTagSection7FindULLENS_3KeyERKy, version APTPKG_6.0 文章目录 问题描述报错分析解决方案:重装你的apt1、查看你的ubuntu版本2、下载适配你的ap…...
Unity 上好用的插件
PlayerMaker BehaviorDesigner Cinemachine Timeline Hybrid Addressable AssetBundle Blower Simple Zoom 大地图上缩放和平移使用ScrollRect的好效果实现...
大数据机器学习算法和计算机视觉应用07:机器学习
Machine Learning Goal of Machine LearningLinear ClassificationSolutionNumerical output example: linear regressionStochastic Gradient DescentMatrix Acceleration Goal of Machine Learning 机器学习的目标 假设现在有一组数据 x i , y i {x_i,y_i} xi,yi&…...
Godot RPG 游戏开发指南
Godot RPG 游戏开发指南 一、基础准备 1. 开发环境 下载并安装最新版 Godot 4.x选择使用 GDScript 或 C# 作为开发语言准备基础美术资源(角色、地图、道具等) 2. 项目结构 project/ ├── scenes/ # 场景文件 ├── scripts/ # 脚…...
c++ 找第一个只出现一次的字符
【题目描述】 给定一个只包含小写字母的字符串,请你找到第一个仅出现一次的字符。如果没有,输出no。 【输入】 一个字符串,长度小于100000。 【输出】 输出第一个仅出现一次的字符,若没有则输出no。 【输入样例】 abcabd【输出样…...
时空信息平台架构搭建:基于netty封装TCP通讯模块(IdleStateHandler网络连接监测,处理假死)
文章目录 引言I 异步TCP连接操作II 心跳机制:空闲检测(读空闲和写空闲)基于Netty的IdleStateHandler类实现心跳机制(网络连接监测)常规的处理假死健壮性的处理假死方案获取心跳指令引言 基于netty实现TCP客户端:封装断线重连、连接保持 https://blog.csdn.net/z92911896…...
【Rust自学】3.6. 控制流:循环
3.6.0. 写在正文之前 欢迎来到Rust自学的第三章,一共有6个小节,分别是: 变量与可变性数据类型:标量类型数据类型:复合类型函数和注释控制流:if else控制流:循环(本文) 通过第二章…...
如何正确计算显示器带宽需求
1. 对显示器的基本认识 一个显示器的参数主要有这些: 分辨率:显示器屏幕上像素点的总数,通常用横向像素和纵向像素的数量来表示,比如19201080(即1080p)。 刷新率:显示器每秒钟画面更新的次数&…...
mysql 基于chunk机制是如何支持运行期间,动态调整buffer pool大小的
mysql 基于chunk机制是如何支持运行期间,动态调整buffer pool大小的 MySQL 的 InnoDB 存储引擎确实支持在运行期间动态调整缓冲池(buffer pool)的大小,但其机制与自定义缓存系统有所不同。InnoDB 通过内部优化和配置参数来实现这…...
梳理你的思路(从OOP到架构设计)_简介设计模式
目录 1、 模式(Pattern) 是较大的结构编辑 2、 结构形式愈大 通用性愈小编辑 3、 从EIT造形 组合出设计模式 1、 模式(Pattern) 是较大的结构 组合与创新 達芬奇說:簡單是複雜的終極形式 (Simplicity is the ultimate form of sophistication) —Leonardo d…...
【Redis】缓存
什么是缓存 https://tech.meituan.com/2017/03/17/cache-about.html Spring Data Redis Spring Data Redis提供了从Spring应用程序轻松配置和访问Redis的功能。 引入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>sp…...
基于 PyCharm 和 Navicat 的新闻管理系统
# 用于创建连接池 pip3 install mysql-connector-python # 改变终端打印颜色 pip3 install colorama 1.创建连接池 文件地址:db/mysql_db.py 首先建立一个与 MySQL 数据库的连接池,以便在应用程序中复用连接,提高性能。 如果连接池创建失败…...
<QNAP 453D QTS-5.x> 日志记录: 优化性能 内存管理 修改swap优先顺序 swap放在ssd 网络稳定性 进程出错管理
起因 几个月前,开始重学编程,往 NAS 的 docker 里放了些 containers ,每一个用来跑练习的 App。为了放更多的app,上个月加了 4GB 内存。最近只放了两个,NAS 就会时不时的闪断。codes 全存在网络驱动器上,当…...
一区牛顿-拉夫逊算法+分解+深度学习!VMD-NRBO-Transformer-GRU多变量时间序列光伏功率预测
一区牛顿-拉夫逊算法分解深度学习!VMD-NRBO-Transformer-GRU多变量时间序列光伏功率预测 目录 一区牛顿-拉夫逊算法分解深度学习!VMD-NRBO-Transformer-GRU多变量时间序列光伏功率预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.中科院一区…...
本地部署webrtc应用怎么把http协议改成https协议?
环境: WSL2 Ubuntu22.04 webrtc视频聊天应用 问题描述: 本地部署webrtc应用怎么把http协议改成https协议? http协议在安卓手机浏览器上用不了麦克风本,来地应用webrtc 本来是http协议,在安卓手机上浏览器不支持使…...
React简单了解
原理简化了解 import React from "react" import { createRoot } form "react-dom/client"const element React.createElement(p,{id: hello},Hello World! )const container document.querySelector(#root) const root createRoot(container) root.r…...
基于LabVIEW的USRP信道测量开发
随着无线通信技术的不断发展,基于软件无线电的设备(如USRP)在信道测量、无线通信测试等领域扮演着重要角色。通过LabVIEW与USRP的结合,开发者可以实现信号生成、接收及信道估计等功能。尽管LabVIEW提供了丰富的信号处理工具和图形…...
Docker挂载
目录 数据卷挂载 本地目录挂载 数据卷挂载 宿主机默认的存放所有容器数据卷的目录:/var/lib/docker/volumes nginx容器 静态文件目录:/usr/share/nginx/html 配置文件目录:/etc/nginx/nginx.conf 修改宿主机的内容,进入到容器查…...
使用Java结合经纬度位置计算目标点的日出日落时间
目录 前言 一、应用示例 1、天安门升旗时间 2、湖南省日出日落信息 二、JAVA日出日落计算 1、在线API 2、使用Java进行计算 三、总结 前言 随着城市化进程的加速,城市环境与人类生活的联系日益紧密。城市不仅承载着居住、工作、休闲等多种功能,也…...
八字精批api接口_php获取生成八字和批注的方法研究
八字算命 API 介绍 这个八字算命 API 提供了一种便捷的方式,让用户通过 GET 或 POST 请求获取详细的八字信息。API 返回的数据格式为 JSON,包含多种命理分析和建议,适合对传统命理学感兴趣的用户。 API 功能 五行分析: 提供用户…...
docker run 命令参数
user docker run -it --nameubn18 --gpus all --privilegedtrue --shm-size 8G ubuntu:18.04 /bin/bash-it 是什么意思 4o 在运行 docker run 命令时,-it 是两个选项的组合,用于更好地与容器进行交互: -i 或 --interactive:这个选…...
智能外呼技术如何改变企业营销方式
智能外呼技术如何改变企业营销方式 作者:开源大模型智能呼叫中心系统FreeAICC,Github:https://github.com/FreeIPCC/FreeAICC 在数字化时代,企业营销方式正经历着前所未有的变革。其中,智能外呼技术作为一项前沿的人…...
redis数据转移
可能有时候因为硬件的原因我们我们需要更换服务器,如果更换服务器的话,那我们redis的数据该怎样转移呢,按照一下步骤即可完成redis数据的转移 1.进入redis客户端 2.使用 bgsave命令进行数据的备份,此命令完成后会在你的redis安装目…...
STM32-笔记5-按键点灯(中断方法)
1、复制03-流水灯项目,重命名06-按键点灯(中断法) 在\Drivers\BSP目录下创建一个文件夹exti,在该文件夹下,创建两个文件exti.c和exti.h文件,并且把这两个文件加载到项目中,打开项目工程文件 加载…...
DotNetBrowser 3.0.0 正式发布!
🛠️ 重要消息:DotNetBrowser 3.0.0 正式发布! 我们很高兴向您介绍全新的 DotNetBrowser 3.0.0 版本。此次更新带来了多项重要功能与优化,进一步提升了 Web 开发的效率和体验。 📢 DotNetBrowser 3.0.0 包含哪些新功…...
MySQL基础笔记(三)
在此特别感谢尚硅谷-康师傅的MySQL精品教程 获取更好的阅读体验请前往我的博客主站! 如果本文对你的学习有帮助,请多多点赞、评论、收藏,你们的反馈是我更新最大的动力! 创建和管理表 1. 基础知识 1.1 一条数据存储的过程 存储数据是处理数…...
SEO初学者-搜索引擎如何工作
搜索引擎基础搜索引擎是如何建立索引的搜索引擎如何对网页进行排名搜索引擎是如何个性化搜索结果的 搜索引擎的工作方式是使用网络爬虫抓取数十亿个页面。爬虫也称为蜘蛛或机器人,它们在网络上导航并跟踪链接以查找新页面。然后,这些页面会被添加到搜索引…...
在Ubuntu下运行QEMU仿真FreeBSD riscv64系统
在Ubuntu下运行QEMU仿真FreeBSD riscv64系统 突发奇想,尝试在Ubuntu下运行QEMU仿真FreeBSD riscv64系统, 参考这篇文档:手把手教你在QEMU上运行RISC-V Linux_qemu 运行 .bin-CSDN博客 并参考FreeBSD的Wiki:riscv - FreeBSD Wik…...
SQL 使用带聚集函数的联结
聚集函数用于汇总数据,通常用于从一个表中计算统计信息,但也可以与联结一起使用。以下是一个例子,展示如何使用聚集函数统计每个顾客的订单数。 示例 1:使用 COUNT() 函数与 INNER JOIN 假设我们需要检索所有顾客及每个顾客所下…...
Linux网络功能 - 服务和客户端程序CS架构和简单web服务示例
By: fulinux E-mail: fulinux@sina.com Blog: https://blog.csdn.net/fulinus 喜欢的盆友欢迎点赞和订阅! 你的喜欢就是我写作的动力! 目录 概述准备工作扫描服务端有那些开放端口创建客户端-服务器设置启动服务器和客户端进程双向发送数据保持服务器进程处于活动状态设置最小…...
爬取Q房二手房房源信息
文章目录 1. 实战概述2. 网站页面分析3. 编写代码爬取Q房二手房房源信息3.1 创建项目与程序3.2 运行程序,查看结果 4. 实战小结 1. 实战概述 本次实战项目旨在通过编写Python爬虫程序,抓取深圳Q房网上的二手房房源信息。我们将分析网页结构,…...
【JavaEE初阶】线程 和 thread
本节⽬标 认识多线程 掌握多线程程序的编写 掌握多线程的状态 一. 认识线程(Thread) 1概念 1) 线程是什么 ⼀个线程就是⼀个 "执⾏流". 每个线程之间都可以按照顺序执⾏⾃⼰的代码. 多个线程之间 "同时" 执⾏着多份代码. 还…...
【IMU:视觉惯性SLAM系统】
视觉惯性SLAM系统简介 相机(单目/双目/RGBD)与IMU结合起来就是视觉惯性,通常以单目/双目IMU为主。 IMU里面有个小芯片可以测量角速度与加速度,可分为6轴(6个自由度)和9轴(9个自由度)IMU,具体的关于IMU的介…...
【python实现烟花】
可以使用 Python 的 turtle 模块来实现烟花效果。下面是一个简单的示例代码,展示如何用 turtle 绘制烟花: import turtle import random# 设置屏幕 screen turtle.Screen() screen.bgcolor("black")# 创建烟花函数 def draw_firework(x, y):…...
OpenCV学习——图像融合
import cv2 as cv import cv2 as cvbg cv.imread("test_images/background.jpg", cv.IMREAD_COLOR) fg cv.imread("test_images/forground.png", cv.IMREAD_COLOR)# 打印图片尺寸 print(bg.shape) print(fg.shape)resize_size (1200, 800)bg cv.resize…...
CS 144 check6: buiding an IP router
Lecture Notes Exercises 路由器的任务是根据路由表转发接收到的数据报:路由表是一系列规则,用于指导路由器针对任何给定的数据报应如何进行转发。 发送出什么接口。下一跳的IP地址。 这个check的工作是实现一个路由器,它可以为任何给定的…...
Pytorch | 从零构建ResNet对CIFAR10进行分类
Pytorch | 从零构建ResNet对CIFAR10进行分类 CIFAR10数据集ResNet核心思想网络结构创新点优点应用 ResNet结构代码详解结构代码代码详解BasicBlock 类ResNet 类ResNet18、ResNet34、ResNet50、ResNet101、ResNet152函数 训练过程和测试结果代码汇总resnet.pytrain.pytest.py 前…...
Spring整合Redis基本操作步骤
Spring 整合 Redis 操作步骤总结 1. 添加依赖 首先,在 pom.xml 文件中添加必要的 Maven 依赖。Redis 相关的依赖包括 Spring Boot 的 Redis 启动器和 fastjson(如果需要使用 Fastjson 作为序列化工具): <!-- Spring Boot Re…...
java中的方法的重载和重写、构造器
目录 方法的重载和重写、构造器1.java的修饰符:2.普通方法3.构造器(也叫构造方法/构造函数)4.方法的重载5.补充6.方法的重写7.类的执行顺序8.再看方法的重写 方法的重载和重写、构造器 1.java的修饰符: public修饰的代码…...
Vite 系列课程|1课程道路,2什么是构建工具
Vite 系列课程 1. 课程导论 1.1 为什么要学习 Vite? 1.1.1 Webpack vs. Vite:新旧霸主的交替? Webpack 长期以来一直是前端构建工具的事实标准,拥有庞大的用户群体、成熟的生态系统和丰富的学习资源。然而,随着前端技术…...
【蓝桥杯选拔赛真题96】Scratch风车旋转 第十五届蓝桥杯scratch图形化编程 少儿编程创意编程选拔赛真题解析
目录 scratch风车旋转 一、题目要求 编程实现 二、案例分析 1、角色分析 2、背景分析 3、前期准备 三、解题思路 1、思路分析 2、详细过程 四、程序编写 五、考点分析 六、推荐资料 1、入门基础 2、蓝桥杯比赛 3、考级资料 4、视频课程 5、python资料 scratc…...
SQL血缘解析
Druid 作为使用率特别高的的数据库连接池工具,在具备完善的连接池管理功能外,同时Druid 的 SQL解析功能可以用来防止 SQL注入等安全风险。通过对 SQL 语句进行解析和检查,Druid 可以识别并阻止潜在的恶意 SQL 语句执行,黑名单(阻止特定的 SQL 语句执行)、白名单(仅允许特…...