url from sender/tab, better per-extension errors (#44)

* url from sender/tab, better per-extension errors

* Remove debug log
This commit is contained in:
Jaco Greeff 2019-06-02 15:36:16 +02:00 committed by GitHub
parent 1a18a2eebb
commit e7c6272e98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { InjectedAccount, InjectedAccountWithMeta, InjectedExtension, InjectedExtensionInfo, InjectedWindow, Unsubcall } from './types';
import { InjectedAccount, InjectedAccountWithMeta, InjectedExtension, InjectedWindow, Unsubcall } from './types';
// our extension adaptor for other kinds of extensions
import compatInjector from './compat';
@ -44,9 +44,12 @@ export function web3Enable (originName: string): Promise<Array<InjectedExtension
web3EnablePromise = compatInjector().then(() =>
Promise.all(
Object.entries(win.injectedWeb3).map(([name, { enable, version }]) =>
Promise
.all([Promise.resolve({ name, version }), enable(originName)])
.catch(() => [{ name, version }, null] as [InjectedExtensionInfo, null])
Promise.all([
Promise.resolve({ name, version }),
enable(originName).catch((error: Error) => {
console.error(`Error initializing ${name}: ${error.message}`);
})
])
)
)
.then((values) =>

View File

@ -12,10 +12,7 @@
},
"content_scripts": [{
"js": ["content.js"],
"matches": [
"https://polkadot.js.org/apps/*",
"http://localhost:3000/*"
],
"matches": ["http://*/*", "https://*/*"],
"run_at": "document_start"
}],
"icons": {

View File

@ -27,7 +27,7 @@ export default function handler ({ id, message, request }: MessageRequest, port:
const sender = port.sender as chrome.runtime.MessageSender;
const from = isPopup
? 'popup'
: sender.tab && sender.tab.url;
: (sender.tab && sender.tab.url) || sender.url;
const source = `${from || FALLBACK_URL}: ${id}: ${message}`;
console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);