据我所知,个人数据始终保存在配置文件路径中,可以在 chrome://version 找到。
我在 Chrome 开发工具中添加了许多代码片段,并且想要备份它们。
但是我找不到保存在此路径下的数据片段的文件。
有人知道吗?请告诉我 。非常感谢!
从 Chrome 47(左右)开始,片段不再可以通过 localStorage 获得。另外,natchiketa 的答案依赖于 localStorage,也不再有效。
以下是当前技术:
InspectorFrontendHost.getPreferences(_ => console.log(JSON.parse(_.scriptSnippets)))
InspectorFrontendHost.setPreference("scriptSnippets", JSON.stringify(yourSnippets))
此技术是从讨论此更改的 github 线程中提取的。
在
ubuntu
中,chromium
片段保存在首选项 .json
文件中。
可能的地点:
~/.config/chromium/Default/Preferences
~/snap/chromium/common/chromium/Default/Preferences
(啪)要查找
Preferences
的确切位置,您可以在 Profile Path
页面中检查属性 chrome://version/
,然后将 /Preferences
附加到它。
(
Preferences
和Bookmarks
是我平时备份的文件)
片段在 .json 路径下保存为序列化的 json:
.devtools.preferences.scriptSnippets
该值需要再次解析为 json,然后你会得到一个与片段相对应的
{name,content}
对数组。
注意:我使用
jq-1.6
来执行以下命令
将所有片段备份到一个 json 文件中:
jq .devtools.preferences.scriptSnippets ~/.config/chromium/Default/Preferences \
| jq '. | fromjson' > /tmp/backup.json
将所有片段备份到单独的.js文件中(每个片段一个)
# Tested with jq-1.6
# The script converts json entries into lines of format
# `filename[TAB]content-in-base64` and then
# for each line creates the corresponding file
# with the content decoded.
# Better be in a safe directory!!
mkdir /tmp/snippets-backup
cd /tmp/snippets-backup
jq .devtools.preferences.scriptSnippets ~/.config/chromium/Default/Preferences \
| jq '. | fromjson | .[]| [ .name, @base64 "\(.content)" ] | @tsv' -r \
| xargs -I{} /bin/bash -c 'file=$(echo "{}"|cut -f1); fileContent=$(echo "{}"|cut -f2); echo "$fileContent" | base64 -d > "${file}.js"'
关于jqjq
是一个很棒的命令行工具,用于查询和处理 JSON 文件。您可以从 stedolan.github.io/jq/ 获取它。
编辑(2016 年 1 月)警告:我只能从最近的反对票中假设这不再起作用。有机会我会更新的。
TL;博士
[{id: n, name: 'foo.js', content: "The script"}]
的数组OS X 的说明如下
# 如果您不知道 Chrome 配置文件是什么,您可能会使用配置文件 1,因此: cd ~/Library/Application\ Support/Google/Chrome/Profile\ 1/Local\ Storage
在此目录中,您应该有一个名为
chrome-devtools_devtools_0.localstorage
的文件,如果是这样,您应该能够执行以下操作:
sqlite3 chrome-devtools_devtools_0.localstorage
...您应该处于 sqlite shell 中,它的开头如下:
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
您可以执行
.tables
查看此文件中的表格:
sqlite> .tables
ItemTable
然后您可以执行以下操作来查看该表中的列名称:
PRAGMA table_info(ItemTable);
由于 localStorage 只是一个键/值存储,因此该表非常简单:
0|key|TEXT|0||0
1|value|BLOB|1||0
更有启发性的是查看关键名称:
select key from ItemTable;
你应该看到这样的东西:
fileSystemMapping
showAdvancedHeapSnapshotProperties
lastDockState
resourcesLargeRows
networkResourceTypeFilters
pauseOnCaughtException
showInheritedComputedStyleProperties
elementsPanelSplitViewState
filterBar-networkPanel-toggled
networkLogColumnsVisibility
networkPanelSplitViewState
sourcesPanelDebuggerSidebarSplitViewState
pauseOnExceptionEnabled
watchExpressions
breakpoints
consoleHistory
domBreakpoints
Inspector.drawerSplitViewState
InspectorView.splitViewState
WebInspector.Drawer.lastSelectedView
currentDockState
editorInDrawerSplitViewState
experiments
inspectorVersion
lastActivePanel
sourcesPanelSplitViewState
sourcesPanelNavigatorSplitViewState
scriptSnippets_lastIdentifier
previouslyViewedFiles
revision-history
revision-history|Script snippet #1|20267.2|1410876616909
scriptSnippets
片段位于
scriptsSnippets
。当我开始这样做时,我没有片段,所以我没有看到这个键。创建我的第一个片段后,密钥出现了。接下来我做了:
select * from ItemTable where key = 'scriptSnippets';
瞧瞧!
scriptSnippets|[{"id":"1","name":"SnipFoo.js","content":"/**\n * @license\n * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>\n * Build: `lodash modern -o ./dist/lodash.js`\n * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>\n * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>\n * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n * Available under MIT license <http://lodash.com/license>\n */\n;(function() {\n\n /** Used as a safe reference for `undefined` in pre ES5 environments */\n var undefined;\n\n /** Used to pool arrays and objects used internally */\n var arrayPool = [],\n objectPool = [];\n\n /** Used to generate unique IDs */\n var idCounter = 0;\n\n /** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */\n var keyPrefix = +new Date + '';\n\n /** Used as the size when optimizations are enabled for large arrays */\n var largeArraySize = 75;\n\n /** Used as the max size of the `arrayPool` and `objectPool` */\n var maxPoolSize = 40;\n\n /** Used to detect and test whitespace */\n var whitespace = (\n // whitespace\n ' \\t\\x0B\\f\\xA0\\ufeff' +\n\n // line terminators\n '\\n\\r\\u2028\\u2029' +\n\n // unicode category \"Zs\" space separators\n '\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\
...等等。请注意,您将看到多个版本的代码片段。我刚刚将
lodash.js
粘贴到我上面提到的新片段中,并且已经有两次了。
那么,如何真正从中获取脚本呢?好吧,一旦获得
value
字段,它就只是一个 JSON 数组,其中有一个片段
id
、name
和 content
。因此,创建一个 SQL 脚本以从命令行传递到 sqlite3
,如下所示:echo "select value from ItemTable where key = 'scriptSnippets';" > showSnippets.txt
然后像这样输入该脚本:
sqlite3 chrome-devtools_devtools_0.localstorage < showSnippets.txt
如果你这样做的话,看起来会稍微漂亮一些:
sqlite3 chrome-devtools_devtools_0.localstorage < showSnippets.txt | python -m json.tool
/Users/yourUserName/Library/Application Support/Google/Chrome/Default/Preferences
Chrome 将您的片段保存在首选项中。
:这个答案是过时的,片段不再保存在本地存储中。 请参阅
paulirish的回答。 对于旧版本的 Chrome,这可能有效。 它存储在这里 C:\Users\Webdev\AppData\Local\Google\Chrome\User Data\Default\Local Storag