多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# chrome.history chorme.history 模块被用于和浏览器所访问的页面记录交互。你可以添加、删除、查询浏览器的历史记录。如果您想覆写历史页面,请查看 [Override替代页](override.html). ## Manifest 您必须在扩展Manifest文件中定义"history"许可,以便使用history API. 如下所示: ``` { "name": "My extension", ... **"permissions": [ "history" ]**, ... } ``` ## 过渡类型 History API用一种过渡类型来描述浏览器是如何访问的特定的URL。例如:如果URL是在用户访问页面时,点击链接跳转访问的,此时的过渡类型为 "link"。 如下的列表详细定义了各种过渡类型。. | 过渡类型 | 描述 | | --- | --- | | "link" | 用户通过点击页面中的链接,跳转至本URL | | "typed" | 用户通过地址栏输入网址,来访问本URL。这种类型也适用于显式的导航动作。与之相反,你可以参阅[generated](#tt_generated),它适用于用户没看到(不知道)网址URL的情况。 | | "auto_bookmark" | 用户通过界面的推荐到达本URL。例如,通过点击菜单项打开的页面。 | | "auto_subframe" | 子框架导航。这种类型是指那些非顶层框架自动加载的内容。例如,如果一个页面由许多包含广告的子框架构成, 那些广告链就拥有这种过渡类型。用户可能没有意识到页面中的这些内容是个单独的框架,所以他们也可能根本没有在意这些URL(请查阅 [manual_subframe](#tt_manual_subframe))。 | | "manual_subframe" | 此种类型是为用户显式请求的子框架导航以及在前进/后退列表中的生成导航入口的子框架导航所设置。由于用户更关心所请求框架被加载的效果,因此显式请求的框架可能会比自动载入的框架更为重要。 | | "generated" | 用户通过在地址栏输入,而选择一个不像网址的入口到达的URL页面。例如,匹配结果中可能包含Google搜索结果页的URL, 但是它可能以"Google 搜索"的形式展现。这类导航和 [typed](#tt_typed) 导航是有差异的,因为用户没有输入或者看到最终的URL。请参阅 [keyword](#tt_keyword)。 | | "start_page" | 页面是在命令行中被指定(打开),或者其本身就是起始页。 | | "form_submit" | 用户提交的表单。请注意,某些情况,诸如表单运用脚本来提交,不属于此种类型。 | | "reload" | 用户通过点击刷新按钮或者在地址栏输入回车键来刷新页面属于此种类型。会话重置,重开标签页都属于此种类型。 | | "keyword" | URL通过可替代的关键字,而不是默认的搜索引擎产生。请查阅[keyword_generated](#tt_keyword_generated) 。 | | "keyword_generated" | 相应由关键字生成的访问。请查阅 [keyword](#tt_keyword)。 | ## 示例 请查看 [history 样例目录](http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/history/) 和 [history API 测试目录](http://src.chromium.org/viewvc/chrome/trunk/src/chrome/test/data/extensions/api_test/history/) 中如何使用 API 的例子。 如果想获取源代码中的样例及帮助,请查看 [样例](samples.html)。 ## API reference: chrome.history ### Properties <a></a> #### getLastError chrome.extensionlastError ### Methods #### addUrl void chrome.history.addUrl(, object `details`) Undocumented. 在当前历史记录中添加一条过渡类型为"link"的URL。 #### Parameters `details`_( optional enumerated Type array of object )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `url`_( optional enumerated Type array of string )_ Undocumented. 要添加的URL。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function The callback _parameter_ should specify a function that looks like this: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function(Type param1, Type param2) {...}; ``` This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### deleteAll void chrome.history.deleteAll(, function `callback`) Undocumented. 删除历史记录中的所有条目。 #### Parameters `callback`_( optional enumerated Type array of function )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function 回调函数的_参数_应当如下定义: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function() {...}; ``` This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### deleteRange void chrome.history.deleteRange(, object `range`, function `callback`) Undocumented. 删除特定日期范围内的所有历史记录条目。页面本身只会在所有访问均在所设定日期的范围内才会被删除。 #### Parameters `range`_( optional enumerated Type array of object )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `startTime`_( optional enumerated Type array of number )_ Undocumented. 条目添加起始时间, 以纪元开始的毫秒数表示。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `endTime`_( optional enumerated Type array of number )_ Undocumented. 条目添加终止时间, 以纪元开始的毫秒数表示。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `callback`_( optional enumerated Type array of function )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function 回调函数的_参数_应当如下定义: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function() {...}; ``` This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### deleteUrl void chrome.history.deleteUrl(, object `details`) Undocumented. 删除指定URL 的所有历史记录。 #### Parameters `details`_( optional enumerated Type array of object )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `url`_( optional enumerated Type array of string )_ Undocumented. 要删除的URL。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function The callback _parameter_ should specify a function that looks like this: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function(Type param1, Type param2) {...}; ``` This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### getVisits void chrome.history.getVisits(, object `details`, function `callback`) Undocumented. 获取访问特定URL的所有信息。 #### Parameters `details`_( optional enumerated Type array of object )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `url`_( optional enumerated Type array of string )_ Undocumented. 需要获取访问信息的URL。URL 必须与历史记录搜索的返回值格式一致。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `callback`_( optional enumerated Type array of function )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function 回调函数的_参数_应当如下定义: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function(array of VisitItem results) {...}; ``` `results`_( optional enumerated Type array of [VisitItem](history.html#type-VisitItem) array of paramType paramType )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### search void chrome.history.search(, object `query`, function `callback`) Undocumented. 搜索历史中,匹配条件的最后一次访问的页面。 #### Parameters `query`_( optional enumerated Type array of object )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `text`_( optional enumerated Type array of string )_ Undocumented. 历史服务的文字查询。若想获取所有页面的信息,把此参数设置为空。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `startTime`_( optional enumerated Type array of number )_ Undocumented. 限制结果访问日期至此日期之后, 以纪元开始的毫秒数表示。. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `endTime`_( optional enumerated Type array of number )_ Undocumented. 限制结果访问日期至此日期以前, 以纪元开始的毫秒数表示。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `maxResults`_( optional enumerated Type array of integer )_ Undocumented. 所获取结果的最大数目。 默认值为100。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `callback`_( optional enumerated Type array of function )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### Returns #### Callback function 回调函数的_参数_应当如下定义: If you specify the _callback_ parameter, it should specify a function that looks like this: ``` function(array of HistoryItem results) {...}; ``` `results`_( optional enumerated Type array of [HistoryItem](history.html#type-HistoryItem) array of paramType paramType )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. This function was added in version . If you require this function, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. ### Events #### onVisitRemoved chrome.history.onVisitRemoved.addListener(function(object removed) {...}); Undocumented. 当一条或着多条URL从历史服务中删除,此事件触发。当所有访问被移除后, 此条URL从来历史记录中被移除。 #### Parameters `removed`_( optional enumerated Type array of object )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `allHistory`_( optional enumerated Type array of boolean )_ Undocumented. 如需删除所有历史记录,则设置成 True。如果设置成true, 所有url 为空。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `urls`_( optional enumerated Type array of Type array of string paramType )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. #### onVisited chrome.history.onVisited.addListener(function(HistoryItem result) {...}); Undocumented. 当URL 被访问时,此事件被触发。并提供相应URL的HistoryItem数据。 #### Parameters `result`_( optional enumerated [HistoryItem](history.html#type-HistoryItem) array of paramType )_ Undocumented. Description of this parameter from the json schema. This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. ### Types #### HistoryItem `paramName`_( optional enumerated Type array of object )_ Undocumented. 封装历史查询结果的对象。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `id`_( optional enumerated Type array of string )_ Undocumented. 条目的唯一标识符。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `url`_( optional enumerated Type array of string )_ Undocumented. 用户所访问的URL。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `title`_( optional enumerated Type array of string )_ Undocumented. 历史页面的标题。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `lastVisitTime`_( optional enumerated Type array of number )_ Undocumented. 页面被载入的最后时间, 以纪元开始的毫秒数表示。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `visitCount`_( optional enumerated Type array of integer )_ Undocumented. 用户访问此页面的次数。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `typedCount`_( optional enumerated Type array of integer )_ Undocumented. 用户通过地址栏输入访问目的页面的次数。 #### VisitItem `paramName`_( optional enumerated Type array of object )_ Undocumented. 封装URL访问的对象。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `id`_( optional enumerated Type array of string )_ Undocumented. 条目的唯一标识符。 `visitId`_( optional enumerated Type array of string )_ Undocumented. 访问的唯一标识符。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `visitTime`_( optional enumerated Type array of number )_ Undocumented. 访问的时间, 以纪元开始的毫秒数表示。 `referringVisitId`_( optional enumerated Type array of string )_ Undocumented. 访问来源的 visit_id 。 This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key [minimum_chrome_version](manifest.html#minimum_chrome_version) can ensure that your extension won't be run in an earlier browser version. `transition`_( optional enumerated Type array of string ["link", "typed", "auto_bookmark", "auto_subframe", "manual_subframe", "generated", "start_page", "form_submit", "reload", "keyword", "keyword_generated"] )_ Undocumented. 访问来源的[过渡类型](history.html#transition_types)。