1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 [ 6 { 7 "namespace": "declarativeWebRequest", 8 "description": "Use the <code>chrome.declarativeWebRequest</code> API to intercept, block, or modify requests in-flight. It is significantly faster than the <a href='webRequest.html'><code>chrome.webRequest</code> API</a> because you can register rules that are evaluated in the browser rather than the JavaScript engine with reduces roundtrip latencies and allows higher efficiency.", 9 "documentation_permissions_required": ["declarative", "declarativeWebRequest"], 10 "types": [ 11 { 12 "id": "HeaderFilter", 13 "type": "object", 14 "description": "Filters request headers for various criteria. Multiple criteria are evaluated as a conjunction.", 15 "properties": { 16 "namePrefix": { 17 "description" : "Matches if the header name starts with the specified string.", 18 "type": "string", 19 "optional": true 20 }, 21 "nameSuffix": { 22 "type": "string", 23 "optional": true, 24 "description" : "Matches if the header name ends with the specified string." 25 }, 26 "nameContains": { 27 "choices": [ 28 {"type": "array", "items": {"type": "string"}}, 29 {"type": "string"} 30 ], 31 "optional": true, 32 "description" : "Matches if the header name contains all of the specified strings." 33 }, 34 "nameEquals": { 35 "type": "string", 36 "optional": true, 37 "description" : "Matches if the header name is equal to the specified string." 38 }, 39 "valuePrefix": { 40 "type": "string", 41 "optional": true, 42 "description" : "Matches if the header value starts with the specified string." 43 }, 44 "valueSuffix": { 45 "type": "string", 46 "optional": true, 47 "description" : "Matches if the header value ends with the specified string." 48 }, 49 "valueContains": { 50 "choices": [ 51 {"type": "array", "items": {"type": "string"}}, 52 {"type": "string"} 53 ], 54 "optional": true, 55 "description" : "Matches if the header value contains all of the specified strings." 56 }, 57 "valueEquals": { 58 "type": "string", 59 "optional": true, 60 "description" : "Matches if the header value is equal to the specified string." 61 } 62 } 63 }, 64 { 65 "id": "RequestMatcher", 66 "type": "object", 67 "description": "Matches network events by various criteria.", 68 "properties": { 69 "url": { 70 "$ref": "events.UrlFilter", 71 "description": "Matches if the conditions of the UrlFilter are fulfilled for the URL of the request.", 72 "optional": true 73 }, 74 "firstPartyForCookiesUrl": { 75 "$ref": "events.UrlFilter", 76 "description": "Matches if the conditions of the UrlFilter are fulfilled for the 'first party' URL of the request. The 'first party' URL of a request, when present, can be different from the request's target URL, and describes what is considered 'first party' for the sake of third-party checks for cookies.", 77 "optional": true 78 }, 79 "resourceType": { 80 "type": "array", 81 "optional": true, 82 "description": "Matches if the request type of a request is contained in the list. Requests that cannot match any of the types will be filtered out.", 83 "items": { "type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"] } 84 }, 85 "contentType": { 86 "type": "array", 87 "optional": true, 88 "description": "Matches if the MIME media type of a response (from the HTTP Content-Type header) is contained in the list.", 89 "items": { "type": "string" } 90 }, 91 "excludeContentType": { 92 "type": "array", 93 "optional": true, 94 "description": "Matches if the MIME media type of a response (from the HTTP Content-Type header) is <em>not</em> contained in the list.", 95 "items": { "type": "string" } 96 }, 97 "requestHeaders": { 98 "type": "array", 99 "optional": true, 100 "description": "Matches if some of the request headers is matched by one of the HeaderFilters.", 101 "items": { "$ref": "HeaderFilter" } 102 }, 103 "excludeRequestHeaders": { 104 "type": "array", 105 "optional": true, 106 "description": "Matches if none of the request headers is matched by any of the HeaderFilters.", 107 "items": { "$ref": "HeaderFilter" } 108 }, 109 "responseHeaders": { 110 "type": "array", 111 "optional": true, 112 "description": "Matches if some of the response headers is matched by one of the HeaderFilters.", 113 "items": { "$ref": "HeaderFilter" } 114 }, 115 "excludeResponseHeaders": { 116 "type": "array", 117 "optional": true, 118 "description": "Matches if none of the response headers is matched by any of the HeaderFilters.", 119 "items": { "$ref": "HeaderFilter" } 120 }, 121 "thirdPartyForCookies": { 122 "type": "boolean", 123 "optional": true, 124 "description": "If set to true, matches requests that are subject to third-party cookie policies. If set to false, matches all other requests." 125 }, 126 "stages": { 127 "type": "array", 128 "items": { 129 "type": "string", 130 "enum": ["onBeforeRequest", "onBeforeSendHeaders", "onHeadersReceived", "onAuthRequired"] 131 }, 132 "optional": true, 133 "description": "Contains a list of strings describing stages. Allowed values are 'onBeforeRequest', 'onBeforeSendHeaders', 'onHeadersReceived', 'onAuthRequired'. If this attribute is present, then it limits the applicable stages to those listed. Note that the whole condition is only applicable in stages compatible with all attributes." 134 }, 135 "instanceType": { 136 "type": "string", "enum": ["declarativeWebRequest.RequestMatcher"], 137 "nodoc": true 138 } 139 } 140 }, 141 { 142 "id": "CancelRequest", 143 "description": "Declarative event action that cancels a network request.", 144 "type": "object", 145 "properties": { 146 "instanceType": { 147 "type": "string", "enum": ["declarativeWebRequest.CancelRequest"], 148 "nodoc": true 149 } 150 } 151 }, 152 { 153 "id": "RedirectRequest", 154 "description": "Declarative event action that redirects a network request.", 155 "type": "object", 156 "properties": { 157 "instanceType": { 158 "type": "string", "enum": ["declarativeWebRequest.RedirectRequest"], 159 "nodoc": true 160 }, 161 "redirectUrl": { "type": "string", "description": "Destination to where the request is redirected."} 162 } 163 }, 164 { 165 "id": "declarativeWebRequest.RedirectToTransparentImage", 166 "description": "Declarative event action that redirects a network request to a transparent image.", 167 "type": "object", 168 "properties": { 169 "instanceType": { 170 "type": "string", "enum": ["declarativeWebRequest.RedirectToTransparentImage"], 171 "nodoc": true 172 } 173 } 174 }, 175 { 176 "id": "declarativeWebRequest.RedirectToEmptyDocument", 177 "description": "Declarative event action that redirects a network request to an empty document.", 178 "type": "object", 179 "properties": { 180 "instanceType": { 181 "type": "string", "enum": ["declarativeWebRequest.RedirectToEmptyDocument"], 182 "nodoc": true 183 } 184 } 185 }, 186 { 187 "id": "declarativeWebRequest.RedirectByRegEx", 188 "description": "Redirects a request by applying a regular expression on the URL. The regular expressions use the <a href=\"http://code.google.com/p/re2/wiki/Syntax\">RE2 syntax</a>.", 189 "type": "object", 190 "properties": { 191 "instanceType": { 192 "type": "string", "enum": ["declarativeWebRequest.RedirectByRegEx"], 193 "nodoc": true 194 }, 195 "from": { 196 "type": "string", 197 "description": "A match pattern that may contain capture groups. Capture groups are referenced in the Perl syntax ($1, $2, ...) instead of the RE2 syntax (\\1, \\2, ...) in order to be closer to JavaScript Regular Expressions." 198 }, 199 "to": { 200 "type": "string", 201 "description": "Destination pattern." 202 } 203 } 204 }, 205 { 206 "id": "declarativeWebRequest.SetRequestHeader", 207 "description": "Sets the request header of the specified name to the specified value. If a header with the specified name did not exist before, a new one is created. Header name comparison is always case-insensitive. Each request header name occurs only once in each request.", 208 "type": "object", 209 "properties": { 210 "instanceType": { 211 "type": "string", "enum": ["declarativeWebRequest.SetRequestHeader"], 212 "nodoc": true 213 }, 214 "name": { 215 "type": "string", 216 "description": "HTTP request header name." 217 }, 218 "value": { 219 "type": "string", 220 "description": "HTTP request header value." 221 } 222 } 223 }, 224 { 225 "id": "declarativeWebRequest.RemoveRequestHeader", 226 "description": "Removes the request header of the specified name. Do not use SetRequestHeader and RemoveRequestHeader with the same header name on the same request. Each request header name occurs only once in each request.", 227 "type": "object", 228 "properties": { 229 "instanceType": { 230 "type": "string", "enum": ["declarativeWebRequest.RemoveRequestHeader"], 231 "nodoc": true 232 }, 233 "name": { 234 "type": "string", 235 "description": "HTTP request header name (case-insensitive)." 236 } 237 } 238 }, 239 { 240 "id": "declarativeWebRequest.AddResponseHeader", 241 "description": "Adds the response header to the response of this web request. As multiple response headers may share the same name, you need to first remove and then add a new response header in order to replace one.", 242 "type": "object", 243 "properties": { 244 "instanceType": { 245 "type": "string", "enum": ["declarativeWebRequest.AddResponseHeader"], 246 "nodoc": true 247 }, 248 "name": { 249 "type": "string", 250 "description": "HTTP response header name." 251 }, 252 "value": { 253 "type": "string", 254 "description": "HTTP response header value." 255 } 256 } 257 }, 258 { 259 "id": "declarativeWebRequest.RemoveResponseHeader", 260 "description": "Removes all response headers of the specified names and values.", 261 "type": "object", 262 "properties": { 263 "instanceType": { 264 "type": "string", "enum": ["declarativeWebRequest.RemoveResponseHeader"], 265 "nodoc": true 266 }, 267 "name": { 268 "type": "string", 269 "description": "HTTP request header name (case-insensitive)." 270 }, 271 "value": { 272 "type": "string", 273 "description": "HTTP request header value (case-insensitive).", 274 "optional": true 275 } 276 } 277 }, 278 { 279 "id": "declarativeWebRequest.IgnoreRules", 280 "description": "Masks all rules that match the specified criteria.", 281 "type": "object", 282 "properties": { 283 "instanceType": { 284 "type": "string", "enum": ["declarativeWebRequest.IgnoreRules"], 285 "nodoc": true 286 }, 287 "lowerPriorityThan": { 288 "type": "integer", 289 "description": "If set, rules with a lower priority than the specified value are ignored. This boundary is not persisted, it affects only rules and their actions of the same network request stage.", 290 "optional": true 291 }, 292 "hasTag": { 293 "type": "string", 294 "description": "If set, rules with the specified tag are ignored. This ignoring is not persisted, it affects only rules and their actions of the same network request stage. Note that rules are executed in descending order of their priorities. This action affects rules of lower priority than the current rule. Rules with the same priority may or may not be ignored.", 295 "optional": true 296 } 297 } 298 }, 299 { 300 "id": "declarativeWebRequest.SendMessageToExtension", 301 "description": "Triggers the $ref:declarativeWebRequest.onMessage event.", 302 "type": "object", 303 "properties": { 304 "instanceType": { 305 "type": "string", "enum": ["declarativeWebRequest.SendMessageToExtension"], 306 "nodoc": true 307 }, 308 "message": { 309 "type": "string", 310 "description": "The value that will be passed in the <code>message</code> attribute of the dictionary that is passed to the event handler." 311 } 312 } 313 }, 314 { 315 "id": "declarativeWebRequest.RequestCookie", 316 "description": "A filter or specification of a cookie in HTTP Requests.", 317 "type": "object", 318 "properties": { 319 "name": { 320 "type": "string", 321 "description": "Name of a cookie.", 322 "optional": true 323 }, 324 "value": { 325 "type": "string", 326 "description": "Value of a cookie, may be padded in double-quotes.", 327 "optional": true 328 } 329 } 330 }, 331 { 332 "id": "declarativeWebRequest.ResponseCookie", 333 "description": "A specification of a cookie in HTTP Responses.", 334 "type": "object", 335 "properties": { 336 "name": { 337 "type": "string", 338 "description": "Name of a cookie.", 339 "optional": true 340 }, 341 "value": { 342 "type": "string", 343 "description": "Value of a cookie, may be padded in double-quotes.", 344 "optional": true 345 }, 346 "expires": { 347 "type": "string", 348 "description": "Value of the Expires cookie attribute.", 349 "optional": true 350 }, 351 "maxAge": { 352 "type": "number", 353 "description": "Value of the Max-Age cookie attribute", 354 "optional": true 355 }, 356 "domain": { 357 "type": "string", 358 "description": "Value of the Domain cookie attribute.", 359 "optional": true 360 }, 361 "path": { 362 "type": "string", 363 "description": "Value of the Path cookie attribute.", 364 "optional": true 365 }, 366 "secure": { 367 "type": "string", 368 "description": "Existence of the Secure cookie attribute.", 369 "optional": true 370 }, 371 "httpOnly": { 372 "type": "string", 373 "description": "Existence of the HttpOnly cookie attribute.", 374 "optional": true 375 } 376 } 377 }, 378 { 379 "id": "declarativeWebRequest.FilterResponseCookie", 380 "description": "A filter of a cookie in HTTP Responses.", 381 "type": "object", 382 "properties": { 383 "name": { 384 "type": "string", 385 "description": "Name of a cookie.", 386 "optional": true 387 }, 388 "value": { 389 "type": "string", 390 "description": "Value of a cookie, may be padded in double-quotes.", 391 "optional": true 392 }, 393 "expires": { 394 "type": "string", 395 "description": "Value of the Expires cookie attribute.", 396 "optional": true 397 }, 398 "maxAge": { 399 "type": "number", 400 "description": "Value of the Max-Age cookie attribute", 401 "optional": true 402 }, 403 "domain": { 404 "type": "string", 405 "description": "Value of the Domain cookie attribute.", 406 "optional": true 407 }, 408 "path": { 409 "type": "string", 410 "description": "Value of the Path cookie attribute.", 411 "optional": true 412 }, 413 "secure": { 414 "type": "string", 415 "description": "Existence of the Secure cookie attribute.", 416 "optional": true 417 }, 418 "httpOnly": { 419 "type": "string", 420 "description": "Existence of the HttpOnly cookie attribute.", 421 "optional": true 422 }, 423 "ageUpperBound": { 424 "type": "integer", 425 "description": "Inclusive upper bound on the cookie lifetime (specified in seconds after current time). Only cookies whose expiration date-time is in the interval [now, now + ageUpperBound] fulfill this criterion. Session cookies and cookies whose expiration date-time is in the past do not meet the criterion of this filter. The cookie lifetime is calculated from either 'max-age' or 'expires' cookie attributes. If both are specified, 'max-age' is used to calculate the cookie lifetime.", 426 "minimum": 0, 427 "optional": true 428 }, 429 "ageLowerBound": { 430 "type": "integer", 431 "description": "Inclusive lower bound on the cookie lifetime (specified in seconds after current time). Only cookies whose expiration date-time is set to 'now + ageLowerBound' or later fulfill this criterion. Session cookies do not meet the criterion of this filter. The cookie lifetime is calculated from either 'max-age' or 'expires' cookie attributes. If both are specified, 'max-age' is used to calculate the cookie lifetime.", 432 "minimum": 0, 433 "optional": true 434 }, 435 "sessionCookie": { 436 "type": "boolean", 437 "description": "Filters session cookies. Session cookies have no lifetime specified in any of 'max-age' or 'expires' attributes.", 438 "optional": true 439 } 440 } 441 }, 442 { 443 "id": "declarativeWebRequest.AddRequestCookie", 444 "description": "Adds a cookie to the request or overrides a cookie, in case another cookie of the same name exists already. Note that it is preferred to use the Cookies API because this is computationally less expensive.", 445 "type": "object", 446 "properties": { 447 "instanceType": { 448 "type": "string", "enum": ["declarativeWebRequest.AddRequestCookie"], 449 "nodoc": true 450 }, 451 "cookie": { 452 "$ref": "declarativeWebRequest.RequestCookie", 453 "description": "Cookie to be added to the request. No field may be undefined." 454 } 455 } 456 }, 457 { 458 "id": "declarativeWebRequest.AddResponseCookie", 459 "description": "Adds a cookie to the response or overrides a cookie, in case another cookie of the same name exists already. Note that it is preferred to use the Cookies API because this is computationally less expensive.", 460 "type": "object", 461 "properties": { 462 "instanceType": { 463 "type": "string", "enum": ["declarativeWebRequest.AddResponseCookie"], 464 "nodoc": true 465 }, 466 "cookie": { 467 "$ref": "declarativeWebRequest.ResponseCookie", 468 "description": "Cookie to be added to the response. The name and value need to be specified." 469 } 470 } 471 }, 472 { 473 "id": "declarativeWebRequest.EditRequestCookie", 474 "description": "Edits one or more cookies of request. Note that it is preferred to use the Cookies API because this is computationally less expensive.", 475 "type": "object", 476 "properties": { 477 "instanceType": { 478 "type": "string", "enum": ["declarativeWebRequest.EditRequestCookie"], 479 "nodoc": true 480 }, 481 "filter": { 482 "$ref": "declarativeWebRequest.RequestCookie", 483 "description": "Filter for cookies that will be modified. All empty entries are ignored." 484 }, 485 "modification": { 486 "$ref": "declarativeWebRequest.RequestCookie", 487 "description": "Attributes that shall be overridden in cookies that machted the filter. Attributes that are set to an empty string are removed." 488 } 489 } 490 }, 491 { 492 "id": "declarativeWebRequest.EditResponseCookie", 493 "description": "Edits one or more cookies of response. Note that it is preferred to use the Cookies API because this is computationally less expensive.", 494 "type": "object", 495 "properties": { 496 "instanceType": { 497 "type": "string", "enum": ["declarativeWebRequest.EditResponseCookie"], 498 "nodoc": true 499 }, 500 "filter": { 501 "$ref": "declarativeWebRequest.FilterResponseCookie", 502 "description": "Filter for cookies that will be modified. All empty entries are ignored." 503 }, 504 "modification": { 505 "$ref": "declarativeWebRequest.ResponseCookie", 506 "description": "Attributes that shall be overridden in cookies that machted the filter. Attributes that are set to an empty string are removed." 507 } 508 } 509 }, 510 { 511 "id": "declarativeWebRequest.RemoveRequestCookie", 512 "description": "Removes one or more cookies of request. Note that it is preferred to use the Cookies API because this is computationally less expensive.", 513 "type": "object", 514 "properties": { 515 "instanceType": { 516 "type": "string", "enum": ["declarativeWebRequest.RemoveRequestCookie"], 517 "nodoc": true 518 }, 519 "filter": { 520 "$ref": "declarativeWebRequest.RequestCookie", 521 "description": "Filter for cookies that will be removed. All empty entries are ignored." 522 } 523 } 524 }, 525 { 526 "id": "declarativeWebRequest.RemoveResponseCookie", 527 "description": "Removes one or more cookies of response. Note that it is preferred to use the Cookies API because this is computationally less expensive.", 528 "type": "object", 529 "properties": { 530 "instanceType": { 531 "type": "string", "enum": ["declarativeWebRequest.RemoveResponseCookie"], 532 "nodoc": true 533 }, 534 "filter": { 535 "$ref": "declarativeWebRequest.FilterResponseCookie", 536 "description": "Filter for cookies that will be removed. All empty entries are ignored." 537 } 538 } 539 } 540 ], 541 "functions": [ 542 ], 543 "events": [ 544 { 545 "name": "onRequest", 546 "options": { 547 "supportsListeners": false, 548 "supportsRules": true, 549 "conditions": ["declarativeWebRequest.RequestMatcher"], 550 "actions": [ 551 "declarativeWebRequest.AddRequestCookie", 552 "declarativeWebRequest.AddResponseCookie", 553 "declarativeWebRequest.AddResponseHeader", 554 "declarativeWebRequest.CancelRequest", 555 "declarativeWebRequest.EditRequestCookie", 556 "declarativeWebRequest.EditResponseCookie", 557 "declarativeWebRequest.RedirectRequest", 558 "declarativeWebRequest.RedirectToTransparentImage", 559 "declarativeWebRequest.RedirectToEmptyDocument", 560 "declarativeWebRequest.RedirectByRegEx", 561 "declarativeWebRequest.RemoveRequestCookie", 562 "declarativeWebRequest.RemoveResponseCookie", 563 "declarativeWebRequest.RemoveRequestHeader", 564 "declarativeWebRequest.RemoveResponseHeader", 565 "declarativeWebRequest.SetRequestHeader", 566 "declarativeWebRequest.SendMessageToExtension", 567 "declarativeWebRequest.IgnoreRules" 568 ] 569 } 570 }, 571 { 572 "name": "onMessage", 573 "type": "function", 574 "description": "Fired when a message is sent via $ref:declarativeWebRequest.SendMessageToExtension from an action of the declarative web request API.", 575 "parameters": [ 576 { 577 "type": "object", 578 "name": "details", 579 "properties": { 580 "message": {"type": "string", "description": "The message sent by the calling script."}, 581 "stage": {"type": "string", 582 "enum": ["onBeforeRequest", "onBeforeSendHeaders", "onHeadersReceived", "onAuthRequired"], 583 "description": "The stage of the network request during which the event was triggered."}, 584 "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."}, 585 "url": {"type": "string"}, 586 "method": {"type": "string", "description": "Standard HTTP method."}, 587 "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."}, 588 "parentFrameId": {"type": "integer", "description": "ID of frame that wraps the frame which sent the request. Set to -1 if no parent frame exists."}, 589 "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."}, 590 "type": {"type": "string", "enum": ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"], "description": "How the requested resource will be used."}, 591 "timeStamp": {"type": "number", "description": "The time when this signal is triggered, in milliseconds since the epoch."} 592 } 593 } 594 ] 595 } 596 ] 597 } 598 ] 599