match_patterns.html revision 201ade2fbba22bfb27ae029f4d23fca6ded109a0
1<!DOCTYPE html><!-- This page is a placeholder for generated extensions api doc. Note: 2 1) The <head> information in this page is significant, should be uniform 3 across api docs and should be edited only with knowledge of the 4 templating mechanism. 5 3) All <body>.innerHTML is genereated as an rendering step. If viewed in a 6 browser, it will be re-generated from the template, json schema and 7 authored overview content. 8 4) The <body>.innerHTML is also generated by an offline step so that this 9 page may easily be indexed by search engines. 10--><html xmlns="http://www.w3.org/1999/xhtml"><head> 11 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 12 <link href="css/ApiRefStyles.css" rel="stylesheet" type="text/css"> 13 <link href="css/print.css" rel="stylesheet" type="text/css" media="print"> 14 <script type="text/javascript" src="/third_party/jstemplate/jstemplate_compiled.js"> 15 </script> 16 <script type="text/javascript" src="js/api_page_generator.js"></script> 17 <script type="text/javascript" src="js/bootstrap.js"></script> 18 <script type="text/javascript" src="js/sidebar.js"></script> 19 <title>Match Patterns - Google Chrome Extensions - Google Code</title></head> 20 <body> <div id="gc-container" class="labs"> 21 <div id="devModeWarning"> 22 You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files. 23 </div> 24 <!-- SUBTEMPLATES: DO NOT MOVE FROM THIS LOCATION --> 25 <!-- In particular, sub-templates that recurse, must be used by allowing 26 jstemplate to make a copy of the template in this section which 27 are not operated on by way of the jsskip="true" --> 28 <div style="display:none"> 29 30 <!-- VALUE --> 31 <div id="valueTemplate"> 32 <dt> 33 <var>paramName</var> 34 <em> 35 36 <!-- TYPE --> 37 <div style="display:inline"> 38 ( 39 <span class="optional">optional</span> 40 <span class="enum">enumerated</span> 41 <span id="typeTemplate"> 42 <span> 43 <a> Type</a> 44 </span> 45 <span> 46 <span> 47 array of <span><span></span></span> 48 </span> 49 <span>paramType</span> 50 <span></span> 51 </span> 52 </span> 53 ) 54 </div> 55 56 </em> 57 </dt> 58 <dd class="todo"> 59 Undocumented. 60 </dd> 61 <dd> 62 Description of this parameter from the json schema. 63 </dd> 64 <dd> 65 This parameter was added in version 66 <b><span></span></b>. 67 You must omit this parameter in earlier versions, 68 and you may omit it in any version. If you require this 69 parameter, the manifest key 70 <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a> 71 can ensure that your extension won't be run in an earlier browser version. 72 </dd> 73 74 <!-- OBJECT PROPERTIES --> 75 <dd> 76 <dl> 77 <div> 78 <div> 79 </div> 80 </div> 81 </dl> 82 </dd> 83 84 <!-- FUNCTION PARAMETERS --> 85 <dd> 86 <div></div> 87 </dd> 88 89 </div> <!-- /VALUE --> 90 91 <div id="functionParametersTemplate"> 92 <h5>Parameters</h5> 93 <dl> 94 <div> 95 <div> 96 </div> 97 </div> 98 </dl> 99 </div> 100 </div> <!-- /SUBTEMPLATES --> 101 102 <a id="top"></a> 103 <div id="skipto"> 104 <a href="#gc-pagecontent">Skip to page content</a> 105 <a href="#gc-toc">Skip to main navigation</a> 106 </div> 107 <!-- API HEADER --> 108 <table id="header" width="100%" cellspacing="0" border="0"> 109 <tbody><tr> 110 <td valign="middle"><a href="http://code.google.com/"><img src="images/code_labs_logo.gif" height="43" width="161" alt="Google Code Labs" style="border:0; margin:0;"></a></td> 111 <td valign="middle" width="100%" style="padding-left:0.6em;"> 112 <form action="http://www.google.com/cse" id="cse" style="margin-top:0.5em"> 113 <div id="gsc-search-box"> 114 <input type="hidden" name="cx" value="002967670403910741006:61_cvzfqtno"> 115 <input type="hidden" name="ie" value="UTF-8"> 116 <input type="text" name="q" value="" size="55"> 117 <input class="gsc-search-button" type="submit" name="sa" value="Search"> 118 <br> 119 <span class="greytext">e.g. "page action" or "tabs"</span> 120 </div> 121 </form> 122 123 <script type="text/javascript" src="http://www.google.com/jsapi"></script> 124 <script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script> 125 <script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse&t13n_langs=en"></script> 126 <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse&lang=en"></script> 127 </td> 128 </tr> 129 </tbody></table> 130 131 <div id="codesiteContent" class=""> 132 133 <a id="gc-topnav-anchor"></a> 134 <div id="gc-topnav"> 135 <h1>Google Chrome Extensions (<a href="http://code.google.com/labs/">Labs</a>)</h1> 136 <ul id="home" class="gc-topnav-tabs"> 137 <li id="home_link"> 138 <a href="index.html" title="Google Chrome Extensions home page">Home</a> 139 </li> 140 <li id="docs_link"> 141 <a href="docs.html" title="Official Google Chrome Extensions documentation">Docs</a> 142 </li> 143 <li id="faq_link"> 144 <a href="faq.html" title="Answers to frequently asked questions about Google Chrome Extensions">FAQ</a> 145 </li> 146 <li id="samples_link"> 147 <a href="samples.html" title="Sample extensions (with source code)">Samples</a> 148 </li> 149 <li id="group_link"> 150 <a href="http://groups.google.com/a/chromium.org/group/chromium-extensions" title="Google Chrome Extensions developer forum">Group</a> 151 </li> 152 </ul> 153 </div> <!-- end gc-topnav --> 154 155 <div class="g-section g-tpl-170"> 156 <!-- SIDENAV --> 157 <div class="g-unit g-first" id="gc-toc"> 158 <ul> 159 <li><a href="getstarted.html">Getting Started</a></li> 160 <li><a href="overview.html">Overview</a></li> 161 <li><a href="whats_new.html">What's New?</a></li> 162 <li><h2><a href="devguide.html">Developer's Guide</a></h2> 163 <ul> 164 <li>Browser UI 165 <ul> 166 <li><a href="browserAction.html">Browser Actions</a></li> 167 <li><a href="contextMenus.html">Context Menus</a></li> 168 <li><a href="notifications.html">Desktop Notifications</a></li> 169 <li><a href="omnibox.html">Omnibox</a></li> 170 <li><a href="options.html">Options Pages</a></li> 171 <li><a href="override.html">Override Pages</a></li> 172 <li><a href="pageAction.html">Page Actions</a></li> 173 </ul> 174 </li> 175 <li>Browser Interaction 176 <ul> 177 <li><a href="bookmarks.html">Bookmarks</a></li> 178 <li><a href="cookies.html">Cookies</a></li> 179 <li><a href="events.html">Events</a></li> 180 <li><a href="history.html">History</a></li> 181 <li><a href="management.html">Management</a></li> 182 <li><a href="tabs.html">Tabs</a></li> 183 <li><a href="windows.html">Windows</a></li> 184 </ul> 185 </li> 186 <li>Implementation 187 <ul> 188 <li><a href="a11y.html">Accessibility</a></li> 189 <li><a href="background_pages.html">Background Pages</a></li> 190 <li><a href="content_scripts.html">Content Scripts</a></li> 191 <li><a href="xhr.html">Cross-Origin XHR</a></li> 192 <li><a href="idle.html">Idle</a></li> 193 <li><a href="i18n.html">Internationalization</a></li> 194 <li><a href="messaging.html">Message Passing</a></li> 195 <li><a href="npapi.html">NPAPI Plugins</a></li> 196 </ul> 197 </li> 198 <li>Finishing 199 <ul> 200 <li><a href="hosting.html">Hosting</a></li> 201 <li><a href="external_extensions.html">Other Deployment Options</a></li> 202 </ul> 203 </li> 204 </ul> 205 </li> 206 <li><h2><a href="apps.html">Packaged Apps</a></h2></li> 207 <li><h2><a href="tutorials.html">Tutorials</a></h2> 208 <ul> 209 <li><a href="tut_debugging.html">Debugging</a></li> 210 <li><a href="tut_analytics.html">Google Analytics</a></li> 211 <li><a href="tut_oauth.html">OAuth</a></li> 212 </ul> 213 </li> 214 <li><h2>Reference</h2> 215 <ul> 216 <li>Formats 217 <ul> 218 <li><a href="manifest.html">Manifest Files</a></li> 219 <li class="leftNavSelected">Match Patterns</li> 220 </ul> 221 </li> 222 <li><a href="permission_warnings.html">Permission Warnings</a></li> 223 <li><a href="api_index.html">chrome.* APIs</a></li> 224 <li><a href="api_other.html">Other APIs</a></li> 225 </ul> 226 </li> 227 <li><h2><a href="samples.html">Samples</a></h2></li> 228 <div class="line"> </div> 229 <li><h2>More</h2> 230 <ul> 231 <li><a href="http://code.google.com/chrome/webstore/docs/index.html">Chrome Web Store</a></li> 232 <li><a href="http://code.google.com/chrome/apps/docs/developers_guide.html">Hosted Apps</a></li> 233 <li><a href="themes.html">Themes</a></li> 234 </ul> 235 </li> 236 </ul> 237 </div> 238 <script> 239 initToggles(); 240 </script> 241 242 <div class="g-unit" id="gc-pagecontent"> 243 <div id="pageTitle"> 244 <h1 class="page_title">Match Patterns</h1> 245 </div> 246 <!-- TABLE OF CONTENTS --> 247 <div id="toc" style="display: none; "> 248 <h2>Contents</h2> 249 <ol> 250 <li> 251 <a>h2Name</a> 252 <ol> 253 <li> 254 <a>h3Name</a> 255 </li> 256 </ol> 257 </li> 258 <li> 259 <a href="#apiReference">API reference</a> 260 <ol> 261 <li> 262 <a href="#properties">Properties</a> 263 <ol> 264 <li> 265 <a href="#property-anchor">propertyName</a> 266 </li> 267 </ol> 268 </li> 269 <li> 270 <a href="#methods">Methods</a> 271 <ol> 272 <li> 273 <a href="#method-anchor">methodName</a> 274 </li> 275 </ol> 276 </li> 277 <li> 278 <a href="#events">Events</a> 279 <ol> 280 <li> 281 <a href="#event-anchor">eventName</a> 282 </li> 283 </ol> 284 </li> 285 <li> 286 <a href="#types">Types</a> 287 <ol> 288 <li> 289 <a href="#id-anchor">id</a> 290 </li> 291 </ol> 292 </li> 293 </ol> 294 </li> 295 </ol> 296 </div> 297 <!-- /TABLE OF CONTENTS --> 298 299 <!-- Standard content lead-in for experimental API pages --> 300 <p id="classSummary" style="display: none; "> 301 For information on how to use experimental APIs, see the <a href="experimental.html">chrome.experimental.* APIs</a> page. 302 </p> 303 304 <!-- STATIC CONTENT PLACEHOLDER --> 305 <div id="static"><div id="pageData-name" class="pageData">Match Patterns</div> 306 307<p> 308<a href="content_scripts.html">Content scripts</a> operate on 309a set of URLs defined by match patterns. 310You can put one or more match patterns 311in the <code>"matches"</code> part of 312a content script's section of the manifest. 313This page describes the match pattern syntax — 314the rules you need to follow when you specify 315which URLs your content script affects. 316</p> 317 318<p> 319A match pattern is essentially a URL 320that begins with a permitted scheme (<code>http</code>, 321<code>https</code>, <code>file</code>, or <code>ftp</code>), 322and that can contain '<code>*</code>' characters. 323The special pattern 324<code><all_urls></code> matches any URL 325that starts with a permitted scheme. 326Each match pattern has 3 parts:</p> 327<p></p> 328 329<ul> 330 <li> <em>scheme</em> — 331 for example, <code>http</code> or <code>file</code> 332 or <code>*</code> 333 </li> 334 <li> <em>host</em> — 335 for example, <code>www.google.com</code> 336 or <code>*.google.com</code> 337 or <code>*</code>; 338 if the scheme is <code>file</code>, 339 there is no <em>host</em> part 340 </li> 341 <li> <em>path</em> — 342 for example, <code>/*</code>, <code>/foo* </code>, 343 or <code>/foo/bar </code> 344 </li> 345</ul> 346 347<p>Here's the basic syntax:</p> 348 349<pre><em><url-pattern></em> := <em><scheme></em>://<em><host></em><em><path></em> 350<em><scheme></em> := '*' | 'http' | 'https' | 'file' | 'ftp' 351<em><host></em> := '*' | '*.' <em><any char except '/' and '*'></em>+ 352<em><path></em> := '/' <em><any chars></em> 353</pre> 354 355<p> 356The meaning of '<code>*</code>' depends on whether 357it's in the <em>scheme</em>, <em>host</em>, or <em>path</em> part. 358If the <em>scheme</em> is <code>*</code>, 359then it matches either <code>http</code> or <code>https</code>. 360If the <em>host</em> is just <code>*</code>, 361then it matches any host. 362If the <em>host</em> is <code>*.<em>hostname</em></code>, 363then it matches the specified host or any of its subdomains. 364In the <em>path</em> section, 365each '<code>*</code>' matches 0 or more characters. 366The following table shows some valid patterns. 367</p> 368 369<table class="columns"> 370<tbody> 371<tr> 372 <th style="margin-left:0; padding-left:0">Pattern</th> 373 <th style="margin-left:0; padding-left:0">What it does</th> 374 <th style="margin-left:0; padding-left:0">Examples of matching URLs</th> 375</tr> 376 377<tr> 378 <td> 379 <code>http://*/*</code> 380 </td> 381 382 <td>Matches any URL that uses the <code>http</code> scheme</td> 383 384 <td> 385 http://www.google.com/<br> 386 http://example.org/foo/bar.html 387 </td> 388</tr> 389 390<tr> 391 <td> 392 <code>http://*/foo*</code> 393 </td> 394 395 <td> 396 Matches any URL that uses the <code>http</code> scheme, on any host, 397 as long as the path starts with <code>/foo</code> 398 </td> 399 400 <td> 401 http://example.com/foo/bar.html<br> 402 http://www.google.com/foo<b></b> 403 </td> 404</tr> 405 406<tr> 407 <td> 408 <code>https://*.google.com/foo*bar </code> 409 </td> 410 411 <td> 412 Matches any URL that uses the <code>https</code> scheme, 413 is on a google.com host 414 (such as www.google.com, docs.google.com, or google.com), 415 as long as the path starts with <code>/foo</code> 416 and ends with <code>bar</code> 417 </td> 418 419 <td> 420 http://www.google.com/foo/baz/bar<br> 421 http://docs.google.com/foobar 422 </td> 423</tr> 424 425<tr> 426 <td> 427 <code>http://example.org/foo/bar.html </code> 428 </td> 429 430 <td>Matches the specified URL</td> 431 432 <td> 433 http://example.org/foo/bar.html 434 </td> 435</tr> 436 437<tr> 438 <td> 439 <code>file:///foo*</code> 440 </td> 441 442 <td>Matches any local file whose path starts with <code>/foo</code></td> 443 444 <td> 445 file:///foo/bar.html<br> 446 file:///foo 447 </td> 448</tr> 449 450<tr> 451 <td> 452 <code>http://127.0.0.1/*</code> 453 </td> 454 455 <td> 456 Matches any URL that uses the <code>http</code> scheme 457 and is on the host 127.0.0.1 458 </td> 459 <td> 460 http://127.0.0.1/<br> 461 http://127.0.0.1/foo/bar.html 462 </td> 463</tr> 464 465<tr> 466 <td> 467 <code>*://mail.google.com/* </code> 468 </td> 469 470 <td> 471 Matches any URL that starts with 472 <code>http://mail.google.com</code> or 473 <code>https://mail.google.com</code>. 474 </td> 475 476 <td> 477 http://mail.google.com/foo/baz/bar<br> 478 https://mail.google.com/foobar 479 </td> 480</tr> 481 482<tr> 483 <td> 484 <code><all_urls></code> 485 </td> 486 487 <td> 488 Matches any URL that uses a permitted scheme. 489 (See the beginning of this section for the list of permitted 490 schemes.) 491 </td> 492 <td> 493 http://example.org/foo/bar.html<br> 494 file:///bar/baz.html 495 </td> 496</tr> 497</tbody> 498</table> 499 500<p> 501Here are some examples of <em>invalid</em> pattern matches: 502</p> 503 504<table class="columns"> 505<tbody> 506<tr> 507 <th style="margin-left:0; padding-left:0">Bad pattern</th> 508 <th style="margin-left:0; padding-left:0">Why it's bad</th> 509</tr> 510 511<tr> 512 <td><code>http://www.google.com</code></td> 513 <td>No <em>path</em></td> 514</tr> 515 516<tr> 517 <td><code>http://*foo/bar</code></td> 518 <td>'*' in the <em>host</em> can be followed only by a '.' or '/'</td> 519</tr> 520 521<tr> 522 <td><code>http://foo.*.bar/baz </code></td> 523 <td>If '*' is in the <em>host</em>, it must be the first character</td> 524 </tr> 525 526<tr> 527 <td><code>http:/bar</code></td> 528 <td>Missing <em>scheme</em> separator ("/" should be "//")</td> 529</tr> 530 531<tr> 532 <td><code>foo://*</code></td> 533 <td>Invalid <em>scheme</em></td> 534</tr> 535</tbody> 536</table> 537 538</div> 539 540 <!-- API PAGE --> 541 <div class="apiPage" style="display: none; "> 542 <a name="apiReference"></a> 543 <h2>API reference: chrome.apiname </h2> 544 545 <!-- PROPERTIES --> 546 <div class="apiGroup"> 547 <a name="properties"></a> 548 <h3 id="properties">Properties</h3> 549 550 <div> 551 <a></a> 552 <h4>getLastError</h4> 553 <div class="summary"> 554 <!-- Note: intentionally longer 80 columns --> 555 <span>chrome.extension</span><span>lastError</span> 556 </div> 557 <div> 558 </div> 559 </div> 560 561 </div> <!-- /apiGroup --> 562 563 <!-- METHODS --> 564 <div class="apiGroup" id="methods"> 565 <a name="methods"></a> 566 <h3>Methods</h3> 567 568 <!-- iterates over all functions --> 569 <div class="apiItem"> 570 <a></a> <!-- method-anchor --> 571 <h4>method name</h4> 572 573 <div class="summary"><span>void</span> 574 <!-- Note: intentionally longer 80 columns --> 575 <span>chrome.module.methodName</span>(<span><span>, </span><span></span> 576 <var><span></span></var></span>)</div> 577 578 <div class="description"> 579 <p class="todo">Undocumented.</p> 580 <p> 581 A description from the json schema def of the function goes here. 582 </p> 583 584 <!-- PARAMETERS --> 585 <h4>Parameters</h4> 586 <dl> 587 <div> 588 <div> 589 </div> 590 </div> 591 </dl> 592 593 <!-- RETURNS --> 594 <h4>Returns</h4> 595 <dl> 596 <div> 597 <div> 598 </div> 599 </div> 600 </dl> 601 602 <!-- CALLBACK --> 603 <div> 604 <div> 605 <h4>Callback function</h4> 606 <p> 607 The callback <em>parameter</em> should specify a function 608 that looks like this: 609 </p> 610 <p> 611 If you specify the <em>callback</em> parameter, it should 612 specify a function that looks like this: 613 </p> 614 615 <!-- Note: intentionally longer 80 columns --> 616 <pre>function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>;</pre> 617 <dl> 618 <div> 619 <div> 620 </div> 621 </div> 622 </dl> 623 </div> 624 </div> 625 626 <!-- MIN_VERSION --> 627 <p> 628 This function was added in version <b><span></span></b>. 629 If you require this function, the manifest key 630 <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a> 631 can ensure that your extension won't be run in an earlier browser version. 632 </p> 633 </div> <!-- /description --> 634 635 </div> <!-- /apiItem --> 636 637 </div> <!-- /apiGroup --> 638 639 <!-- EVENTS --> 640 <div class="apiGroup"> 641 <a name="events"></a> 642 <h3 id="events">Events</h3> 643 644 <!-- iterates over all events --> 645 <div class="apiItem"> 646 <a></a> 647 <h4>event name</h4> 648 649 <div class="summary"> 650 <!-- Note: intentionally longer 80 columns --> 651 <span class="subdued">chrome.bookmarks</span><span>onEvent</span><span class="subdued">.addListener</span>(function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>); 652 </div> 653 654 <div class="description"> 655 <p class="todo">Undocumented.</p> 656 <p> 657 A description from the json schema def of the event goes here. 658 </p> 659 660 <!-- PARAMETERS --> 661 <h4>Parameters</h4> 662 <dl> 663 <div> 664 <div> 665 </div> 666 </div> 667 </dl> 668 669 </div> <!-- /decription --> 670 671 </div> <!-- /apiItem --> 672 673 </div> <!-- /apiGroup --> 674 675 <!-- TYPES --> 676 <div class="apiGroup"> 677 <a name="types"></a> 678 <h3 id="types">Types</h3> 679 680 <!-- iterates over all types --> 681 <div class="apiItem"> 682 <a></a> 683 <h4>type name</h4> 684 685 <div> 686 </div> 687 688 </div> <!-- /apiItem --> 689 690 </div> <!-- /apiGroup --> 691 692 </div> <!-- /apiPage --> 693 </div> <!-- /gc-pagecontent --> 694 </div> <!-- /g-section --> 695 </div> <!-- /codesiteContent --> 696 <div id="gc-footer" --=""> 697 <div class="text"> 698 <p> 699 Except as otherwise <a href="http://code.google.com/policies.html#restrictions">noted</a>, 700 the content of this page is licensed under the <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons 701 Attribution 3.0 License</a>, and code samples are licensed under the 702 <a rel="license" href="http://code.google.com/google_bsd_license.html">BSD License</a>. 703 </p> 704 <p> 705 ©2010 Google 706 </p> 707 708<!-- begin analytics --> 709<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script> 710<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script> 711 712<script type="text/javascript"> 713 // chrome doc tracking 714 try { 715 var engdocs = _gat._getTracker("YT-10763712-2"); 716 engdocs._trackPageview(); 717 } catch(err) {} 718 719 // code.google.com site-wide tracking 720 try { 721 _uacct="UA-18071-1"; 722 _uanchor=1; 723 _uff=0; 724 urchinTracker(); 725 } 726 catch(e) {/* urchinTracker not available. */} 727</script> 728<!-- end analytics --> 729 </div> 730 </div> <!-- /gc-footer --> 731 </div> <!-- /gc-container --> 732</body></html> 733